package com.ss.android.video;

import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_BUFFERING_UPDATE;
import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_COMPLETE;
import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_ERROR;
import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_INFO;
import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_MP_EXCEPTION;
import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_PREPARE;
import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_RELEASED;
import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_SEEK_COMPLETE;
import static com.ss.android.video.SSMediaPlayerWrapper.CALLBACK_ON_STATE_ERROR;
import static com.ss.android.video.SSMediaPlayerWrapper.OP_REQUEST_CUR_POSITION;
import static com.ss.android.video.SSMediaPlayerWrapper.OP_REQUEST_DURATION;
import static com.ss.android.video.SSMediaPlayerWrapper.STAT_INITIALIZED;
import static com.ss.android.video.SSMediaPlayerWrapper.STAT_PAUSED;
import static com.ss.android.video.SSMediaPlayerWrapper.STAT_PLAYBACK_COMPLETE;
import static com.ss.android.video.SSMediaPlayerWrapper.STAT_PREPARED;
import static com.ss.android.video.SSMediaPlayerWrapper.STAT_STARTED;
import static com.ss.android.video.SSMediaPlayerWrapper.STAT_STOPPED;

import android.app.Activity;
import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.Toast;

import com.bytedance.article.common.c.JSONObjectWrapper;
import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.NetworkType;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.collection.WeakHandler.Callback;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.bytedance.ttnet.a.NetChannelSelect;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.app.BizApplication;
import com.ss.android.article.base.feature.app.schema.AdsAppActivity;
import com.ss.android.article.base.feature.detail2.DetailIntentCreator;
import com.ss.android.article.base.feature.detail2.DetailPageListener;
import com.ss.android.article.base.feature.e.VideoAutoPlayHelperDetail;
import com.ss.android.article.base.feature.feed.FeedTab;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.CellRef;
import com.ss.android.article.base.feature.video.GetPlayUrlThread;
import com.ss.android.article.base.feature.video.IMediaCallback;
import com.ss.android.article.base.feature.video.IMediaLayout;
import com.ss.android.article.base.feature.video.IVideoController;
import com.ss.android.article.base.feature.video.IVideoFullscreen;
import com.ss.android.article.base.feature.video.MediaHelper;
import com.ss.android.article.base.feature.video.RelatedVideoItem;
import com.ss.android.article.base.feature.video.ThirdVideoPartnerData;
import com.ss.android.article.base.feature.video.VideoClarityHelper;
import com.ss.android.article.base.feature.video.VideoPref;
import com.ss.android.article.base.feature.video.cache.VideoCacheController;
import com.ss.android.article.base.feature.video.cache.VideoCacheManager;
import com.ss.android.article.base.utils.ArticleHelper;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.app.AbsApplication;
import com.ss.android.common.app.IComponent;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.callback.CallbackCenter;
import com.ss.android.common.callback.SSCallback;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.BaseApplication;
import com.ss.android.newmedia.a.AdsAppBaseActivity;
import com.ss.android.newmedia.util.AppUtil;
import com.ss.android.video.a.VideoDiagnosis;
import com.ss.ttvideoengine.b.LiveItem;
import com.ss.ttvideoengine.b.VideoAdInfo;
import com.ss.ttvideoengine.b.VideoDataContainer;
import com.ss.ttvideoengine.b.VideoInfo;
import com.ss.ttvideoengine.b.VideoItem;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;

import okhttp3.SSAppCompatViewInflater;

public class VideoController implements Callback, IMediaCallback, IVideoController {
    private static VideoController instance;
    private static final int PATCH_POSITION_BEFORE = 1;
    private static final int PATCH_POSITION_AFTER = 2;
    private static final int PATCH_POSITION_MIDDLE = 3;
    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public final void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if ("android.intent.action.SCREEN_OFF".equals(action)) {
                VideoController.this.pauseVideo();
            } else if (("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) && (VideoController.this.nonNullContext())) {
                NetworkType networkType = NetworkUtils.getNetworkType(context);
                if ((mMediaLayout == null || !mMediaLayout.isNoWifiDialogShowing())
                        && !AppData.getInstance().userAllowUseMobileNet
                        && networkType != NetworkType.WIFI
                        && networkType != NetworkType.NONE) {
                    Context ctx = mRefContext.get();
                    VideoController.this.pauseVideo();
                    mMediaLayout.showNoWifiNoticeDialog(ctx);
                    AbsApplication application = BaseApplication.getApplication();
                    long v4 = mArticle != null ? mArticle.groupId : 0L;
                    MobClickCombiner.onEvent(application, "video", "net_alert_show", v4, 0L);
                    if (VideoController.this.isLiveVideo) {
                        v4 = mArticle != null ? mArticle.groupId : 0L;
                        MobClickCombiner.onEvent(application, "live", "network_hint", v4, 0L);
                    }
                }
                if (!AppData.getInstance().getAbSettings().isVideoUseIpUrl()) {
                    return;
                }
                NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
                if (networkInfo == null) {
                    return;
                }
                if (!networkInfo.isConnected()) {
                    return;
                }

                int v0_4 = NetChannelSelect.d(context);
                if (v0_4 == VideoController.this.v) {
                    return;
                }

                if (mUsingMediaPlayer == null) {
                    return;
                }

                mUsingMediaPlayer.preResolveInetAddressesFormHttpDns(v0_4);
                VideoController.this.v = v0_4;
            }
        }
    };
    private final Runnable mRequestPositionRunnable = new RequestPositionRunnable(this);
    public boolean isFromFeed;
    WeakReference<Context> mRefContext;
    long mAdId;
    JSONObject mReportJO;
    Article mArticle;
    String mVideoId;
    WeakHandler mWeakHandler = new WeakHandler(this);
    IMediaLayout mMediaLayout;
    SSMediaPlayerWrapper mUsingMediaPlayer;
    boolean j;
    boolean isPrepared = false;
    int mRetryCount = 0;
    ViewGroup mVideoContainer;
    int[] mCoverImageIvLocationInWindow = new int[2];
    int[] mVideoContainerLocationInWindow = new int[2];
    VideoEventReporter mVideoEventReporter;
    VideoStatistics mVideoStatistics;
    WeakReference<ISplashAdListener> mSplashAdListenerRef;
    VideoDataContainer mVideoDataContainer;
    int mPatchPosition = 3;
    boolean isLiveVideo = false;
    int v;
    long mDuration;
    private String mSource;
    private WeakReference<DetailPageListener> mDetailPageListener;
    private String mLogExtra;
    private String mCategoryName;
    private SSMediaPlayerWrapper mAbandonMediaPalyer;
    private GetPlayUrlThread mGetPlayUrlThread;
    private boolean isFullscreen = false;
    private boolean isPlayError = false;
    private boolean isExitintActivity = false;
    private boolean isJellyBeanMR1 = false;
    private boolean K = false;
    private String mVideoSource;
    private long mNewestDragPosition;
    private long mTotalPlayTime = 0;
    private long mStartPlayTs = 0;
    private WeakReference<View> mCoverImageIvRef;
    private WeakReference<View> mVideoContainerRef;
    private boolean R = false;
    private long S = 0;
    private Object mBindedTag;
    private WeakReference<ICloseListener> mCloseListenerRef;
    private WeakReference<IVideoFullscreen> mVideoFullscreenRef;
    private WeakReference<IShareListener> mShareListenerRef;
    private long mDragPosition = 0;
    private boolean Y = false;
    private long mLastVideoPos;
    private boolean shouldPreloadVideo = false;
    private boolean aB = false;
    private int mLoop = 0;
    private int mDragUnit = 5000;
    private int mDefaultDragStep = 10;
    private String mVideoErrorString = null;
    private List mTrackUrlList;
    private String mWid = "";
    private boolean aI = false;
    private VideoAutoPlayHelperDetail mVideoAutoPlayHelperDetail = VideoAutoPlayHelperDetail.getInstance();
    private WeakReference<IPlayCompleteListener> mPlayCompleteListenerRef;
    private long mLoadStartRT;
    private Runnable mSyncPositionRunnable = new Runnable() {

        public final void run() {
            FrameLayout.LayoutParams layoutParams = mMediaLayout.getLayoutParams();
            if (layoutParams != null) {
                layoutParams.topMargin = mCoverImageIvLocationInWindow[1] - mVideoContainerLocationInWindow[1];
                layoutParams.leftMargin = mCoverImageIvLocationInWindow[0];
                layoutParams.gravity = 51;
                mMediaLayout.setLayoutParams(layoutParams);
                mVideoContainer.requestLayout();
            }
        }
    };
    private Runnable RetryPlayRunnable = new Runnable() {

        public final void run() {
            if (mSplashAdListenerRef != null) {
                ISplashAdListener splashAdListener = mSplashAdListenerRef.get();
                if (splashAdListener != null) {
                    splashAdListener.onTimeOut();
                }
            }

            if (isPatchVideo()) {
                VideoController videoController = VideoController.this;
                if (videoController.isPatchVideo()) {
                    if (videoController.mPatchPosition == 1) {
                        videoController.c(false);
                        videoController.f();
                    } else {
                        videoController.onVideoComplete(-1);
                    }
                }
            } else if (!VideoController.this.isPrepared
                    && mVideoDataContainer != null
                    && mVideoDataContainer.mVideoInfo != null
                    && mVideoDataContainer.mVideoInfo.mVideoItem1 != null) {
                if (mRetryCount < 3
                        && mRetryCount + 1 <= AppData.getInstance().mVideoPlayRetryPolicy) {
                    String backupUrl = mVideoDataContainer.mVideoInfo.mVideoItem1.backupUrl1;
                    if (mRetryCount == 1) {
                        backupUrl = mVideoDataContainer.mVideoInfo.mVideoItem1.backupUrl2;
                    } else if (mRetryCount == 2) {
                        backupUrl = mVideoDataContainer.mVideoInfo.mVideoItem1.backupUrl3;
                    }

                    String decodeBackupUrl = MediaHelper.getVideoSource(backupUrl);
                    if (!android.support.design.a.isTextEmpty(decodeBackupUrl)) {
                        Logger.d("VideoController", "retry backup video url");
                        int videoFixONLineQuestionFlage = AppData.getInstance().getAbSettings().getVideoFixONLineQuestionFlage();
                        if (videoFixONLineQuestionFlage == 1) {
                            videoFixONLineQuestionFlage = 1;
                        } else if ((videoFixONLineQuestionFlage & 16) > 0) {
                            videoFixONLineQuestionFlage = 1;
                        } else {
                            videoFixONLineQuestionFlage = 0;
                        }
                        if (videoFixONLineQuestionFlage != 0) {
                            mUsingMediaPlayer.stop();
                        }

                        mUsingMediaPlayer.reset();
                        SSMediaPlayerWrapper.increaseNewPlayerFailTime();
                        if (mVideoStatistics != null) {
                            mVideoStatistics.b();
                            VideoStatistics videoStatistics = mVideoStatistics;
                            String videoId = mVideoId;
                            long v0_4 = videoStatistics.mData == null ? 0L : videoStatistics.mData.optLong("pt");
                            videoStatistics.a();
                            videoStatistics.unregisterConnectivityReceiver();
                            videoStatistics.d = -1;
                            videoStatistics.mData = null;
                            videoStatistics.g = false;
                            videoStatistics.registerConnectivityReceiver(videoId);
                            videoStatistics.setVideoUrl(decodeBackupUrl);
                            videoStatistics.setWid(videoStatistics.wid);
                            if (videoStatistics.mData != null && v0_4 > 0L) {
                                VideoStatistics.a(videoStatistics.mData, "retry_pt", Long.valueOf(v0_4));
                            }
                        }
                        mUsingMediaPlayer.setDataSource(decodeBackupUrl);
                        VideoController.this.playVideo2(true);
                    }

                    ++mRetryCount;
                    long delay = 0L;
                    if (!android.support.design.a.isTextEmpty(decodeBackupUrl)) {
                        delay = AppData.getInstance().mVideoPlayRetryInterval * 1000L;
                    }
                    mWeakHandler.postDelayed(this, delay);
                    if (AppData.getInstance().getAbSettings().isVideoDiagnosisEnabled()) {
                        VideoDiagnosis.performVideoDiagnosis(VideoController.this.getVideoId());
                        return;
                    } else {
                        return;
                    }
                }

                mRetryCount = 0;
                mMediaLayout.dismissLoading();
                mMediaLayout.showRetry();
                if (mVideoStatistics == null) {
                    return;
                }

                mVideoStatistics.b();
                mVideoStatistics.a();
                mVideoStatistics.a(VideoController.this.j);
                if (mUsingMediaPlayer == null) {
                    return;
                }
                mUsingMediaPlayer.release();
            }
        }
    };
    private String mClarityActual = "";
    private long mClarityChangeTime;
    private long mCurrentPosition;
    private long mLastTotalPlayTime = 0;
    private long aU;
    private ReshowEndCoverCallback aV;
    private StopAutoPlayAnimationCallback aW;
    private MyOnAudioFocusChangeListener mMyOnAudioFocusChangeListener;
    private SetAutoRotateCallback mSetAutoRotateCallback;
    private ArrayList mPendingActionList;
    private boolean ab;
    private int mVideoWidth = 0;
    private int mVideoHeight = 0;
    private boolean isPauseFromList = false;
    private boolean pendingPausedVideo = false;
    private String ag;
    private boolean isActivityOnDestroy = false;
    private boolean ai = false;
    private boolean isSurfaceCreated = false;
    private long ak = 0;
    private long mSmallPlayTime = 0;
    private boolean isReceiverRegistered = false;
    private boolean isDirectPlay = false;
    private boolean shouldRequestAudioFocus = true;
    private long mStartDragPosition = 0;
    private String mExternalUrl;
    private boolean ar = false;
    private ThirdVideoPartnerData mThirdVideoPartnerData;
    private WeakReference<IThirdPartnerListner> mRefThirdPartnerListner;
    private boolean av = false;
    private int mDurationSeconds = -1;
    private int mAdJumpCountdown = -1;
    private boolean isPendingPlay = false;
    private boolean isSplashVideoPlaying = false;
    private JSONObject mLogPb;
    private long mSearchResultId = 0;
    private String mQuery;

    private VideoController() {
        this.init();
    }

    public VideoController(Context context, ViewGroup container, boolean isFromFeed) {
        this(context, container, isFromFeed, null);
    }

    public VideoController(Context context, ViewGroup container, boolean isFromFeed, EnumSet enumSet) {
        mRefContext = new WeakReference(context);
        this.init();
        mVideoContainer = container;
        this.isFromFeed = isFromFeed;
        this.initMediaLayout(context, isFromFeed, enumSet);
    }

    public static VideoController getInstance() {
        if (instance == null) {
            synchronized (VideoController.class) {
                if (instance == null) {
                    instance = new VideoController();
                }
            }
        }
        return instance;
    }

    private static VideoItem getVideoItemByClarity(VideoInfo videoInfo) {
        SparseArray<VideoItem> supportVideoInfos = VideoClarityHelper.getSupportVideoInfos(videoInfo);
        VideoItem videoItem = VideoClarityHelper.getVideoInfoWithClarity(supportVideoInfos);
        if (videoItem == null) {
            videoItem = VideoClarityHelper.getVideoInfo(videoInfo, 2);
        }
        return videoItem;
    }

    private static boolean shouldPreloadVideo(Article article) {
        return article.shouldPreloadVideo() || (VideoCacheController.isDebugOpen());
    }

    static boolean a(VideoController videoController) {
        return !videoController.isDirectPlay() || !videoController.isFromFeed;
    }

    public static void releaseInstance() {
        instance = null;
    }

    private void initMediaLayout(Context context, boolean isFromFeed, EnumSet enumSet) {
        mMediaLayout = new MediaViewLayout(context,
                SSAppCompatViewInflater.from(context.getApplicationContext()).inflate(com.ss.android.article.browser.R.layout.media_play_layout, null, false),
                isFromFeed,
                enumSet);
        IMediaLayout mediaLayout = mMediaLayout;
        AppData.getInstance();
        mediaLayout.setTheme(AppData.isNightMode());
        mMediaLayout.setCallback(this);
    }

    private String maybeProxyUrl(String url) {
        boolean invalidUrl = !TTUtils.isValidUrl(url);
        if (!invalidUrl && this.shouldPreloadVideo && (AppData.getInstance().shouldPreload()) && !this.isLiveVideo) {
            String videoId = mVideoId;
            String backupUrl2 = null;
            String backupUrl1 = null;
            String backupUrl3 = null;
            if (mVideoDataContainer != null
                    && mVideoDataContainer.mVideoInfo != null) {
                VideoItem videoItem = mMediaLayout == null
                        ? VideoClarityHelper.getVideoInfoWithClarity(VideoClarityHelper.getSupportVideoInfos(mVideoDataContainer.mVideoInfo))
                        : mMediaLayout.getSelectClarity();
                if (videoItem != null) {
                    backupUrl1 = MediaHelper.getVideoSource(videoItem.backupUrl1);
                    backupUrl2 = MediaHelper.getVideoSource(videoItem.backupUrl2);
                    backupUrl3 = MediaHelper.getVideoSource(videoItem.backupUrl3);
                    if (!TextUtils.isEmpty(VideoClarityHelper.getDefinitionStr(videoItem.definition))) {
                        videoId = videoId + VideoClarityHelper.getDefinitionStr(videoItem.definition);
                    }
                }
            }
            VideoCacheManager videoCacheManager = VideoCacheManager.getInstance();
            String[] urls = new String[4];
            urls[0] = url;
            urls[1] = backupUrl1;
            urls[2] = backupUrl2;
            urls[3] = backupUrl3;
            String proxyUrl = videoCacheManager.proxyUrl(videoId, urls);
            if (proxyUrl.startsWith("http://127.0.0.1")) {
                String[] urls2 = new String[4];
                urls2[0] = url;
                urls2[1] = backupUrl1;
                urls2[2] = backupUrl2;
                urls2[3] = backupUrl3;
                videoCacheManager.preDownload(videoId, urls2);
                if (mVideoStatistics != null) {
                    VideoStatistics videoStatistics = mVideoStatistics;
                    videoStatistics.appendParam("sv", SSMediaPlayerWrapper.mediaPlayerType == 0 ? "1.1" : "2.1");
                }
            }
            url = proxyUrl;
        }
        return url;
    }

    private void setContainerSize(int width, int height) {
        if (mMediaLayout != null) {
            mMediaLayout.setContainerSize(width, height);
        }
    }

    private void seekTo(long seekTo) {
        if (mUsingMediaPlayer != null) {
            mUsingMediaPlayer.seekTo(seekTo);
        }
    }

    private void refreshTimeUI(long totalPlayTime, long duration) {
        if (!this.isFromFeed || !this.isDirectPlay()) {
            if (mDurationSeconds <= 0) {
                mDurationSeconds = (int) duration / 1000;
            }

            mMediaLayout.setTimeDesc(totalPlayTime, duration);
            mMediaLayout.setSeekProgress(MediaHelper.timeToPercent(totalPlayTime, duration));
            if (TextUtils.equals(mVideoId, VideoPref.getLastVideoId())) {
                VideoPref.setLastVideoPos(totalPlayTime);
            }
            if (!this.isPatchVideo()) {
                this.aU = mDuration;
                return;
            }
            int newPlaySeconds = (int) (totalPlayTime - mLastTotalPlayTime) / 1000;
            if (newPlaySeconds <= 0) {
                return;
            }
            mLastTotalPlayTime = totalPlayTime;
            mDurationSeconds -= newPlaySeconds;
            mAdJumpCountdown -= newPlaySeconds;
            if (mAdJumpCountdown <= 0) {
                mMediaLayout.updateAdLeftTime((int) ((duration - totalPlayTime) / 1000L), -1);
            } else {
                mMediaLayout.updateAdLeftTime((int) ((duration - totalPlayTime) / 1000L), mAdJumpCountdown);
            }
        }
    }

    private void onEvent(Context context, String event, JSONObject jsonObject) {
        String enterFrom = this.getCategoryLabel("click");
        if (AppData.getInstance().getAbSettings().isAppLogOld()) {
            try {
                if (mArticle != null) {
                    jsonObject.put("item_id", mArticle.itemId);
                    jsonObject.put("aggr_type", mArticle.aggrType);
                    MobClickCombiner.onEvent(context, event, enterFrom, mArticle.groupId, mAdId, jsonObject);
                }
            } catch (JSONException jsonException) {
            }
        }

        if (AppData.getInstance().getAbSettings().isAppLogNew()) {
            JSONObjectWrapper joWrapper = new JSONObjectWrapper();
            String v4 = "group_id";
            long v10 = 0;
            long v0_1 = mArticle != null ? mArticle.groupId : v10;
            joWrapper.put(v4, Long.valueOf(v0_1));
            String v5 = "item_id";
            v0_1 = mArticle != null ? mArticle.itemId : v10;
            joWrapper.put(v5, Long.valueOf(v0_1));
            v4 = "aggr_type";
            int v0_2 = mArticle != null ? mArticle.aggrType : 0;
            joWrapper.put(v4, Integer.valueOf(v0_2)).put("ad_id", Long.valueOf(mAdId)).put("log_pb", mLogPb);
            if (mArticle != null) {
                joWrapper.put("author_id", Long.valueOf(mArticle.getUserId()));
            }

            String categoryName;
            if (enterFrom.equals("click_" + mCategoryName)) {
                enterFrom = "click_category";
                categoryName = mCategoryName;
            } else if (enterFrom.equals("click_headline")) {
                categoryName = mCategoryName;
            } else {
                categoryName = enterFrom.replaceFirst("click_", "");
            }

            if (this.mSearchResultId != v10) {
                joWrapper.put("search_result_id", Long.valueOf(this.mSearchResultId)).put("query", this.mQuery).put("source", this.mSource);
            }

            joWrapper.put("enter_from", enterFrom).put("category_name", categoryName);
            if (AppData.getInstance().getAbSettings().isApplogStaging()) {
                joWrapper.put("_staging_flag", Integer.valueOf(1));
            }
            joWrapper.put(jsonObject);
            android.support.design.a.onEvent(event, joWrapper.jo);
        }
    }

    private void executeOrPendingAction(Runnable runnable) {
        if (!mMediaLayout.isSurfaceViewValid() || !this.ai) {
            if (mPendingActionList == null) {
                mPendingActionList = new ArrayList();
            }
            mPendingActionList.add(runnable);
        } else {
            runnable.run();
        }
    }

    private void playVideo(String url, String videoId, int sp) {
        mVideoId = videoId;
        if (this.isDirectPlay()) {
            mMediaLayout.setDirectPlay(true);
            mMediaLayout.dismissToolBar(false, false);
            mMediaLayout.trySetTitleVisiable(false);
        } else if (this.av) {
            mMediaLayout.dismissToolBar(false, !this.isPatchVideo());
            mMediaLayout.trySetTitleVisiable(false);
        } else if (this.isLiveVideo) {
            mMediaLayout.dismissToolBar(false, false);
        }
        if (this.isLiveVideo) {
            AbsApplication application = BaseApplication.getApplication();
            long groupId = mArticle != null ? mArticle.groupId : 0L;
            MobClickCombiner.onEvent(application, "live", "loading", groupId, 0L);
        }
        if (mArticle != null && mArticle.mLoadingCoverImageInfo != null) {
            mMediaLayout.showLoadingCover(mArticle.mLoadingCoverImageInfo);
        }
        mMediaLayout.showLoading();

        VideoCacheController.getInstance().parseUrlFromArticleIfNeed(mArticle);
        VideoDataContainer videoDataContainer = VideoCacheController.getInstance().getDataContainer(videoId);
        if (videoDataContainer != null) {
            mVideoDataContainer = videoDataContainer;
            if (this.shouldPreloadVideo && VideoCacheController.getInstance().hasFailed(videoId)) {
                this.shouldPreloadVideo = false;
            }
        }

        if (!TextUtils.isEmpty(url)) {
            try {
                this.startPlayVideo(URLDecoder.decode(url, "UTF-8"));
            } catch (UnsupportedEncodingException unsupportedEncodingException) {
            }
            return;
        }

        if (videoDataContainer != null) {
            this.f();
            return;
        }

        long itemId = mArticle != null ? mArticle.itemId : 0L;
        String category = mCategoryName;
        int playType = !this.isLiveVideo ? 1 : 2;
        mGetPlayUrlThread = new GetPlayUrlThread(mWeakHandler, sp, videoId, itemId, category, playType, mAdId, true);
        mGetPlayUrlThread.start();
        if (android.support.design.a.isTest(BizApplication.getApplication())) {
            Log.e("url_cache", "get url from network!");
        }
    }

    private void onEvent(String event, JSONObject jsonObject) {
        this.onEvent(BaseApplication.getApplication(), event, jsonObject);
    }

    private void appendClarityArgs(JSONObject jsonObject) {
        String clarityChoose;
        if (mVideoDataContainer != null && mVideoDataContainer.mVideoInfo != null) {
            try {
                jsonObject.put("clarity_num", mMediaLayout.getClarityCount());
                if (VideoClarityHelper.isAutoMode()) {
                    jsonObject.put("clarity_choose", "AUTO");
                } else {
                    switch (VideoClarityHelper.getDefaultVideoClarity()) {
                        case 0:
                            clarityChoose = "720p";
                            break;
                        case 1:
                            clarityChoose = "480p";
                            break;
                        default:
                            clarityChoose = "360p";
                            break;
                    }

                    jsonObject.put("clarity_choose", clarityChoose);
                }
                jsonObject.put("clarity_actual", mClarityActual);
                jsonObject.put("clarity_change_time", MediaHelper.timeToPercent(mClarityChangeTime, mDuration));
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
            mClarityChangeTime = 0;
        }
    }

    final void onVideoComplete(int arg25) {
        if (TextUtils.equals(mVideoId, VideoPref.getLastVideoId())) {
            VideoPref.setLastVideoId(null);
            VideoPref.setLastVideoPos(-1);
        }

        DetailPageListener detailPageListener = mDetailPageListener == null ? null : mDetailPageListener.get();
        if (!this.isFromFeed && detailPageListener != null) {
            detailPageListener.onVideoCompletion(true);
        }

        if (this.nonNullContext()) {
            Context context = mRefContext.get();
            if (!(context instanceof IComponent)) {
                return;
            }

            if (mMediaLayout == null) {
                return;
            }

            if (((IComponent) context).isDestroyed()) {
                return;
            }

            if (!this.isFromFeed
                    && !this.isLiveVideo
                    && !this.o()
                    && mVideoAutoPlayHelperDetail != null
                    && mVideoAutoPlayHelperDetail.a(this.isFullscreen, this.isAd(), mThirdVideoPartnerData)
                    && this.isFullscreen) {
                VideoAutoPlayHelperDetail.dismissVolumeOrTouchView(mMediaLayout);
            } else if (this.isFullscreen) {
                if ((!this.o()) || mThirdVideoPartnerData != null) {
                    this.isFullscreen = false;
                    if (!this.isFromFeed && detailPageListener != null) {
                        detailPageListener.onFullscreenChanged(this.isFullscreen);
                    }

                    if (mMediaLayout != null) {
                        mMediaLayout.exitFullScreen(mVideoContainer);
                    }

                    this.requestOrienation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                    IVideoFullscreen videoFullscreen = mVideoFullscreenRef != null ? mVideoFullscreenRef.get() : null;
                    if (videoFullscreen != null) {
                        videoFullscreen.onFullscreenChanged(this.isFullscreen);
                    }
                    if (mVideoEventReporter != null) {
                        mVideoEventReporter.onEvent(this.isFromFeed ? "feed_fullscreen_exit_normal" : "detail_fullscreen_exit_normal");
                    }
                }
            }
            mMediaLayout.setKeepScreenOn(false);
            mMediaLayout.disableAutoRotate();
            this.removeRequestPositionRunnable();
            if (mPatchPosition != 1) {
                mMediaLayout.setIsPatchVideo(false, false);
            }
            mMediaLayout.setPlayIcon(true, this.isLiveVideo);
            if (!this.isFromFeed || !this.isDirectPlay()) {
                mMediaLayout.setSeekProgress(100);
                mMediaLayout.setTimeDesc(this.aU, this.aU);
                mMediaLayout.removeDismissToolBarMsg();
                if (mThirdVideoPartnerData == null || (TextUtils.isEmpty(mThirdVideoPartnerData.packageName)) || (TextUtils.isEmpty(mThirdVideoPartnerData.androidOpenUrl)) || (TextUtils.isEmpty(mThirdVideoPartnerData.androidDownloadUrl))) {
                    if (this.av) {
                        mMediaLayout.showToolBar(true, false, !this.isPatchVideo());
                    } else {
                        mMediaLayout.showToolBar(true);
                    }
                } else {
                    boolean isJump;
                    if (ToolUtils.isAppInstalled(BizApplication.getApplication(), mThirdVideoPartnerData.packageName)) {
                        mMediaLayout.setThirdImageUrl(mThirdVideoPartnerData.inBannerOpenImgUrl);
                        isJump = true;
                    } else {
                        mMediaLayout.setThirdImageUrl(mThirdVideoPartnerData.inBannerDownloadImgUrl);
                        isJump = false;
                    }

                    if (mRefThirdPartnerListner != null) {
                        IThirdPartnerListner thirdPartnerListner = mRefThirdPartnerListner.get();
                        if (thirdPartnerListner != null) {
                            thirdPartnerListner.onShowEvent(isJump ? "player_show_jump" : "player_show_download");
                        }
                    }
                    mMediaLayout.showToolBar(true, true, false);
                }
                mMediaLayout.dismissLoading();
                mMediaLayout.trySetTitleVisiable(this.isFromFeed);
            } else {
                mMediaLayout.releaseMediaPlayer();
            }

            if (this.isLiveVideo) {
                String txt = context.getResources().getString(com.ss.android.article.browser.R.string.live_video_error_end);
                mMediaLayout.showLiveError(txt, !isFromFeed);
            }

            if (!this.isPlayError
                    && mArticle != null
                    && mArticle.groupId > 0) {
                if (this.isFromFeed) {
                    View videoContainer;
                    if (mVideoContainerRef == null) {
                        videoContainer = null;
                    } else {
                        videoContainer = mVideoContainerRef.get();
                    }
                    mMediaLayout.showRelatedVideo(this.getBindedTag(), videoContainer);
                    if (AppData.getInstance().getAbSettings().isUseVideoFinishNewUI()
                            && mAdId <= 0
                            && !this.isLiveVideo
                            && mThirdVideoPartnerData == null) {
                        mMediaLayout.showNewCover(mArticle);
                    }
                } else if (mPatchPosition == 2) {
                    mMediaLayout.showCover(mArticle.largeImageList, this.isFromFeed);
                    if (AppData.getInstance().getAbSettings().isUseVideoFinishNewUI()
                            && mAdId <= 0
                            && !this.isLiveVideo
                            && mThirdVideoPartnerData == null) {
                        mMediaLayout.showNewCover(mArticle);
                    }
                } else if (mPatchPosition == 3 && !this.hasAfterPatchVideo()) {
                    mMediaLayout.showCover(mArticle.largeImageList, this.isFromFeed);
                    if (AppData.getInstance().getAbSettings().isUseVideoFinishNewUI()
                            && mAdId <= 0
                            && !this.isLiveVideo
                            && mThirdVideoPartnerData == null) {
                        mMediaLayout.showNewCover(mArticle);
                    }
                }
            }

            this.j = true;
            JSONObject joo = null;
            long adLeave = 0;
            if (mVideoStatistics != null) {
                if (mDuration - mCurrentPosition > 2000) {
                    mVideoStatistics.d();
                }
                joo = mVideoStatistics.c();
                if (joo == null) {
                    adLeave = 0L;
                } else if (!joo.has("vt")) {
                    adLeave = 0L;
                } else {
                    try {
                        adLeave = joo.getLong("vt");
                    } catch (Exception exception) {
                    }
                }
            }
            String backupUrl;
            if (this.isPlayError) {
                if (mLoop > 0) {
                    backupUrl = null;
                } else {
                    if (!android.support.design.a.fixOnLineQuestion() && this.isPrepared) {
                        backupUrl = null;
                    } else if (!NetworkUtils.isWifi(BizApplication.getApplication())) {
                        backupUrl = null;
                    } else if (mLoop <= 0 && mVideoDataContainer != null
                            && mVideoDataContainer.mVideoInfo != null
                            && mVideoDataContainer.mVideoInfo.mVideoItem1 != null) {
                        if (android.support.design.a.isTextEmpty(mVideoDataContainer.mVideoInfo.mVideoItem1.backupUrl1)
                                && android.support.design.a.isTextEmpty(mVideoDataContainer.mVideoInfo.mVideoItem1.backupUrl2)) {
                            backupUrl = null;
                        } else if (android.support.design.a.isTextEmpty(mVideoDataContainer.mVideoInfo.mVideoItem1.backupUrl1)) {
                            backupUrl = mVideoDataContainer.mVideoInfo.mVideoItem1.backupUrl2;
                        } else {
                            backupUrl = mVideoDataContainer.mVideoInfo.mVideoItem1.backupUrl1;
                        }
                    } else {
                        backupUrl = null;
                    }
                }

                if (!android.support.design.a.isTextEmpty(backupUrl)) {
                    if ((this.isPrepared) && (android.support.design.a.fixOnLineQuestion())) {
                        mLastVideoPos = this.getCurrentPlayPosition();
                    }
                    ++mLoop;
                    mUsingMediaPlayer.reset();
                    this.isPlayError = false;
                    this.shouldPreloadVideo = false;
                    this.startPlayVideo(MediaHelper.getVideoSource(backupUrl));
                    return;
                }

                String errorTxt;
                if (!NetworkUtils.isNetworkAvailable(context)) {
                    errorTxt = context.getString(com.ss.android.article.browser.R.string.video_mobile_codec_error) + -977;
                } else if (arg25 == -10000) {
                    errorTxt = context.getString(com.ss.android.article.browser.R.string.video_mobile_codec_error) + -976;
                } else {
                    errorTxt = context.getString(com.ss.android.article.browser.R.string.video_mobile_codec_error) + -975;
                }

                if (mVideoDataContainer != null && !android.support.design.a.isTextEmpty(mVideoId) && (this.shouldPreloadVideo)) {
                    this.shouldPreloadVideo = false;
                    VideoCacheController.getInstance().setPlayFailFlag(mVideoId);
                }

                UIUtils.showImageToast(context, errorTxt);
                if (AppData.getInstance().getAbSettings().isVideoDiagnosisEnabled()) {
                    new VideoDiagnosis(mVideoId, mVideoSource, errorTxt, mVideoErrorString, joo).start();
                }
                this.releaseMedia(false);
            }

            if (mVideoEventReporter != null) {
                if (!this.isFromFeed || this.isFromFeed && !this.isDirectPlay()) {
                    mVideoEventReporter.onEvent(isFromFeed ? "feed_over" : "detail_over");
                }

                if (this.isFromFeed && this.isDirectPlay() && this.ar) {
                    mVideoEventReporter.onEvent("feed_over");
                }
            }

            JSONObject jo = new JSONObject();
            try {
                if (mStartPlayTs > 0) {
                    mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                    mStartPlayTs = 0;
                }

                if (0 > 0) {
                    this.ak = System.currentTimeMillis();
                    mSmallPlayTime += this.ak;
                }

                jo.put("duration", mTotalPlayTime - mSmallPlayTime);
                if (this.j) {
                    jo.put("percent", 100);
                } else {
                    jo.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                }

                jo.put("small_play_time", mSmallPlayTime);
                jo.put("log_extra", mLogExtra);
                if (mArticle != null && mArticle.videoSubjectId > 0) {
                    jo.put("video_subject_id", mArticle.videoSubjectId);
                }
            } catch (Exception exception) {
            }

            if (mSplashAdListenerRef != null) {
                ISplashAdListener splashAdListener = mSplashAdListenerRef.get();
                if (splashAdListener != null) {
                    splashAdListener.onComplete(mTotalPlayTime, MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                }
            }

            JSONObject jsonObject = null;
            if (mAdId > 0) {
                if (!this.isSplashVideoPlaying) {
                    if (!this.isFromFeed || (this.isFromFeed) && !this.isDirectPlay()) {
                        if (this.isPatchVideo()) {
                            MobAdClickCombiner.onAdEvent(context,
                                    "embeded_ad", this.isFromFeed ? "patch_feed_over" : "patch_detail_over",
                                    mAdId, 0, jo, 0);
                        } else {
                            MobAdClickCombiner.onAdEvent(context,
                                    "embeded_ad", this.isFromFeed ? "feed_over" : "detail_over",
                                    mAdId, 0, jo, 0);
                        }
                    }
                    if (!this.isFromFeed) {
                    } else if (!this.isDirectPlay()) {
                    } else if (!this.ar) {
                    } else {
                        AbsApplication application = BaseApplication.getApplication();
                        MobAdClickCombiner.onAdEvent(application,
                                "embeded_ad",
                                this.isPatchVideo() ? "patch_feed_over" : "feed_over",
                                mAdId,
                                0,
                                jo,
                                0);
                    }
                } else {
                    try {
                        jsonObject = new JSONObject();
                        jsonObject.put("log_extra", mLogExtra);
                        jsonObject.put("duration", mTotalPlayTime);
                        jsonObject.put("percent", MediaHelper.timeToPercent(mTotalPlayTime, mDuration));
                    } catch (JSONException jsonException) {
                        jsonException.printStackTrace();
                    }
                    MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "splash_ad", "play_over", mAdId, 0, jsonObject, 3);
                }
            }
            try {
                jo.put("position", this.isFromFeed ? "list" : "detail");
                this.appendClarityArgs(jo);
            } catch (JSONException jsonException) {
            }

            if (mArticle != null) {
                try {
                    jo.put("item_id", mArticle.itemId);
                    jo.put("aggr_type", mArticle.aggrType);
                } catch (JSONException jsonException) {
                }

                if (!this.isFromFeed || (this.isFromFeed) && !this.isDirectPlay()) {
                    if (!this.j()) {
                        this.onEvent("video_over", jo);
                    } else if (!this.isFromFeed && mVideoAutoPlayHelperDetail != null) {
                        Context ctx;
                        if (mRefContext == null) {
                            ctx = null;
                        } else {
                            ctx = mRefContext.get();
                        }
                        mVideoAutoPlayHelperDetail.onEvent(ctx, this.getCategoryLabel("click"), mArticle.groupId, mAdId, jo);
                    }
                }

                if (this.isDirectPlay) {
                    jsonObject = new JSONObject();
                    try {
                        jsonObject.put("duration", mTotalPlayTime);
                        jsonObject.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                        jsonObject.put("log_extra", mLogExtra);
                        jsonObject.put("position", this.isFromFeed ? "list" : "detail");
                        jsonObject.put("item_id", mArticle.itemId);
                        if (mArticle.videoSubjectId > 0) {
                            jsonObject.put("video_subject_id", mArticle.videoSubjectId);
                        }
                        this.appendClarityArgs(jsonObject);
                    } catch (Exception exception) {
                    }

                    String event;
                    if (this.isFromFeed) {
                        event = this.ar ? "feed_back_play_over" : "feed_play_over";
                    } else {
                        event = "auto_detail_play_over";
                    }

                    if (mAdId > 0) {
                        MobAdClickCombiner.onAdEvent(context, "embeded_ad", event, mAdId, 0, jsonObject, 0);
                    } else {
                        MobClickCombiner.onEvent(context, "video_over", event, mArticle.groupId, 0, jsonObject);
                    }

                    if (this.isFromFeed && this.ar) {
                        this.onEvent(context, "video_over", jo);
                    }
                }
            }
            if (this.isDirectPlay() && this.isFromFeed) {
                this.releaseMedia();
                mTotalPlayTime = 0;
                mSmallPlayTime = 0;
            }

            if (mDetailPageListener != null) {
                mDetailPageListener.get();
            }

            if (mPatchPosition == 1) {
                this.c(false);
                mTotalPlayTime = 0;
                mSmallPlayTime = 0;
                if (mVideoStatistics != null) {
                    mVideoStatistics.registerConnectivityReceiver(mVideoId);
                    mVideoStatistics.appendAdLeave(adLeave);
                }

                if (mArticle != null) {
                    this.shouldPreloadVideo = shouldPreloadVideo(mArticle);
                }

                this.f();
            } else {
                if (mPatchPosition == 3) {
                    if (this.hasAfterPatchVideo()) {
                        this.c(false);
                        mTotalPlayTime = 0;
                        mSmallPlayTime = 0;
                        if (mVideoStatistics != null) {
                            mVideoStatistics.registerConnectivityReceiver(mVideoId);
                        }

                        this.playAdUrl(false);
                    } else {
                        this.removeRequestPositionRunnable();
                        this.isPauseFromList = false;
                    }
                } else if (mPatchPosition == 2) {
                    if (mUsingMediaPlayer != null) {
                        mUsingMediaPlayer.release();
                    }

                    this.removeRequestPositionRunnable();
                    mTotalPlayTime = 0;
                    mStartPlayTs = 0;
                    mCurrentPosition = 0;
                    mDuration = 0;
                    this.j = false;
                    this.isPrepared = false;
                    this.isPlayError = false;
                    mNewestDragPosition = 0;
                    this.K = false;
                    mLastVideoPos = -1;
                    mVideoHeight = 0;
                    mVideoWidth = 0;
                    mPatchPosition = -1;
                    this.av = false;
                    mLastTotalPlayTime = 0;
                    mDurationSeconds = 0;
                    mAdJumpCountdown = 0;
                    mAdId = 0;
                    this.isPauseFromList = false;
                    this.unregisterConnectivityReceiver();
                    this.clearPendingActions();
                } else {
                    mTotalPlayTime = 0;
                    mSmallPlayTime = 0;
                }
            }

            if (mVideoAutoPlayHelperDetail != null
                    && !this.o()
                    && !this.isFromFeed
                    && !this.isLiveVideo
                    && (android.support.design.a.hasVideo(mArticle))
                    && mThirdVideoPartnerData == null) {
                if (!this.isAd() || this.isPatchVideo()) {
                    mVideoAutoPlayHelperDetail.a(this, context, this.isFullscreen);
                }

            }
        }
    }

    final void a(boolean arg5) {
        mMediaLayout.setPlayIcon(false, this.isLiveVideo);
        this.shouldRequestAudioFocus = !this.isDirectPlay || !this.isFromFeed;
        if (this.isPatchVideo()) {
            mMediaLayout.updateAdPatchVideoPanel(true);
        }

        if (mUsingMediaPlayer != null) {
            this.playVideo2(arg5);
            mLastVideoPos = -1;
        }

        this.j = false;
        if (!arg5 && mStartPlayTs <= 0) {
            mStartPlayTs = System.currentTimeMillis();
        }
        if (this.isPatchVideo() && arg5) {
            mWeakHandler.postDelayed(this.RetryPlayRunnable, 3000L);
        } else if (arg5 && AppData.getInstance().mVideoPlayRetryPolicy > 0 && TTUtils.isValidUrl(mVideoSource)) {
            mWeakHandler.postDelayed(this.RetryPlayRunnable, AppData.getInstance().mVideoPlayRetryInterval * 1000L);
        }
    }

    private void startPlayVideo(String url) {
        if (this.nonNullContext()) {
            String videoUrl = maybeProxyUrl(url);
            this.pendingPausedVideo = false;
            mVideoSource = videoUrl;
            if (mUsingMediaPlayer != null) {
                mUsingMediaPlayer.setDataSource(videoUrl);
            }

            if ((this.isFromFeed) && (this.isDirectPlay())) {
                mMediaLayout.setDirectPlay(true);
                mMediaLayout.dismissToolBar(false, false);
                mMediaLayout.trySetTitleVisiable(false);
            } else if (this.av) {
                mMediaLayout.dismissToolBar(false, !this.isPatchVideo());
                mMediaLayout.trySetTitleVisiable(false);
            } else if (this.isLiveVideo) {
                mMediaLayout.dismissToolBar(false, false);
            } else {
                mMediaLayout.setDirectPlay(false);
                mMediaLayout.showToolBar(false);
                boolean titleVisible = false;
                if (this.isFromFeed) {
                    titleVisible = !this.isFullScreen();
                }
                mMediaLayout.trySetTitleVisiable(titleVisible);
            }

            if (mAdId <= 0 || (this.isFromFeed) || (android.support.design.a.isTextEmpty(mExternalUrl)) || (this.isPatchVideo())) {
                mMediaLayout.setAdGoLanding(false);
            } else {
                mMediaLayout.setAdGoLanding(true);
            }

            mMediaLayout.dismissCover();

            //travis add start loading页面不会消失
//            mMediaLayout.dismissLoading();
            //travis add end loading页面不会消失

            mMediaLayout.setPlayerSurfaceViewSize(!this.av);
            if (android.support.design.a.isTextEmpty(videoUrl)) {
                return;
            }
            Logger.d("VideoController", "Get Video Source: " + mVideoSource);
            this.isSurfaceCreated = false;
            this.ai = false;
            mMediaLayout.setSurfaceViewVisible(View.GONE);
            mMediaLayout.setSurfaceViewVisible(View.VISIBLE);
            mMediaLayout.setPlayIcon(false, this.isLiveVideo);
            this.executeOrPendingAction(new Runnable() {

                public final void run() {
                    VideoController.this.a(true);
                }
            });
            if (mVideoStatistics != null) {
                mVideoStatistics.setVideoUrl(videoUrl);
            }
        }
    }

    private boolean b(int arg2) {
        return mMediaLayout.outOfBuffer(arg2);
    }

    final void playVideo2(boolean prepareAsync) {
        DetailPageListener detailPageListener = mDetailPageListener == null ? null : mDetailPageListener.get();
        if (!this.isFromFeed && detailPageListener != null) {
            detailPageListener.onVideoCompletion(false);
        }
        if (mPatchPosition != 3 || this.isLiveVideo) {
            mLastVideoPos = -1;
        } else if (!TextUtils.equals(mVideoId, VideoPref.getLastVideoId())) {
            VideoPref.setLastVideoId(mVideoId);
            VideoPref.setLastVideoPos(-1);
        }
        if (this.isDirectPlay() && this.isFromFeed) {
            mMediaLayout.disableAutoRotate();
        } else if (this.isSplashVideoPlaying) {
            mMediaLayout.disableAutoRotate();
        } else {
            mMediaLayout.enableAutoRotate();
        }

        if (mMediaLayout != null) {
            mMediaLayout.setKeepScreenOn(true);
        }

        if (this.shouldRequestAudioFocus) {
            try {
                if (mMyOnAudioFocusChangeListener == null) {
                    mMyOnAudioFocusChangeListener = new MyOnAudioFocusChangeListener();
                    AudioManager audioManager = (AudioManager) AbsApplication.getApplication().getSystemService(Context.AUDIO_SERVICE);
                    audioManager.requestAudioFocus(mMyOnAudioFocusChangeListener, 3, 1);
                }
            } catch (Throwable throwable) {
            }
        } else {
            this.abandonAudioFocus();
        }
        mMediaLayout.setVisibility(View.VISIBLE);
        boolean hasVoice = !this.isSplashVideoPlaying && (!this.isDirectPlay || !this.isFromFeed);
        mUsingMediaPlayer.start(prepareAsync, mLastVideoPos, hasVoice);
        if (mMediaLayout == null || !mMediaLayout.isAutoRotateEnabled()) {
            if (mSetAutoRotateCallback != null) {
                CallbackCenter.addCallback(BaseAppData.callbackTypePopUiShowStateChanged, mSetAutoRotateCallback);
            }
        } else {
            if (mSetAutoRotateCallback == null) {
                mSetAutoRotateCallback = new SetAutoRotateCallback(this);
            }
            CallbackCenter.addCallback(BaseAppData.callbackTypePopUiShowStateChanged, mSetAutoRotateCallback);
        }
    }

    @Override
    public boolean backPress(Activity activity) {
        if (this.isVideoVisible()) {
            if (this.isFullscreen) {
                this.isFullscreen = !this.isFullscreen;
                mMediaLayout.exitFullScreen(mVideoContainer);
                mMediaLayout.trySetTitleVisiable(this.isFromFeed && this.j);
                this.requestOrienation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                String event = this.isFromFeed ? "fullscreen_exit_back_button_list" : "fullscreen_exit_back_button_detail";
                mVideoEventReporter.onEvent(event);
                IVideoFullscreen videoFullscreen = mVideoFullscreenRef != null ? mVideoFullscreenRef.get() : null;
                if (videoFullscreen != null) {
                    videoFullscreen.onFullscreenChanged(this.isFullscreen);
                }
                return true;
            } else {
                if ((activity instanceof FeedTab)) {
                    return false;
                }

                if (this.isFromFeed) {
                    return false;
                }

                if (mRefContext == null) {
                    return false;
                }

                if (mRefContext.get() == null) {
                    return false;
                }

                mVideoEventReporter.onEvent("detail_video_close_key");
                this.releaseMedia();
                this.notifyOnClose();
                return true;
            }
        } else {
            return false;
        }
    }

    final boolean nonNullContext() {
        return mRefContext != null && mRefContext.get() != null;
    }

    final void c(boolean arg21) {
        if (mMediaLayout != null) {
            mMediaLayout.disableAutoRotate();
        }

        if (mGetPlayUrlThread != null) {
            mGetPlayUrlThread.cancelRequest();
        }

        if (mUsingMediaPlayer != null) {
            mUsingMediaPlayer.release();
        }

        if ((this.isFullscreen) && !this.o()) {
            this.isFullscreen = !this.isFullscreen;
            mMediaLayout.exitFullScreen(mVideoContainer);
            this.requestOrienation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            IVideoFullscreen videoFullscreen = mVideoFullscreenRef != null
                    ? mVideoFullscreenRef.get()
                    : null;
            if (videoFullscreen != null) {
                videoFullscreen.onFullscreenChanged(this.isFullscreen);
            }
        }
        mMediaLayout.updateAdPatchVideoPanel(false);
        mMediaLayout.setPlayIcon(true, this.isLiveVideo);
        this.removeRequestPositionRunnable();
        mWeakHandler.removeCallbacks(this.RetryPlayRunnable);
        if (mPatchPosition != PATCH_POSITION_BEFORE) {
            mMediaLayout.setIsPatchVideo(false, false);
        }
        mMediaLayout.setSeekProgress(100);
        mMediaLayout.setTimeDesc(this.aU, this.aU);
        mMediaLayout.removeDismissToolBarMsg();
        if (this.av) {
            mMediaLayout.showToolBar(true, false, !this.isPatchVideo());
        } else {
            mMediaLayout.showToolBar(true);
        }

        mMediaLayout.dismissLoading();
        mMediaLayout.trySetTitleVisiable(this.isFromFeed);
        if (!this.isPlayError && mArticle != null && mArticle.groupId > 0) {
            if (this.isFromFeed) {
                View videoContainer;
                if (mVideoContainerRef == null) {
                    videoContainer = null;
                } else {
                    videoContainer = mVideoContainerRef.get();
                }
                mMediaLayout.showRelatedVideo(this.getBindedTag(), videoContainer);
                if (AppData.getInstance().getAbSettings().isUseVideoFinishNewUI()
                        && mAdId <= 0
                        && !this.isLiveVideo
                        && mThirdVideoPartnerData == null) {
                    mMediaLayout.showNewCover(mArticle);
                }
            } else {
                if (mPatchPosition == PATCH_POSITION_AFTER) {
                    mMediaLayout.showCover(mArticle.largeImageList, this.isFromFeed);
                    if (AppData.getInstance().getAbSettings().isUseVideoFinishNewUI()
                            && mAdId <= 0
                            && !this.isLiveVideo
                            && mThirdVideoPartnerData == null) {
                        mMediaLayout.showNewCover(mArticle);
                    }
                } else if (mPatchPosition == PATCH_POSITION_MIDDLE && !this.hasAfterPatchVideo()) {
                    mMediaLayout.showCover(mArticle.largeImageList, this.isFromFeed);
                    if (AppData.getInstance().getAbSettings().isUseVideoFinishNewUI()
                            && mAdId <= 0
                            && !this.isLiveVideo
                            && mThirdVideoPartnerData == null) {
                        mMediaLayout.showNewCover(mArticle);
                    }
                }
            }
        }
        if (!this.j && !android.support.design.a.isTextEmpty(mVideoId)) {
            if (this.isFromFeed) {
                if (!this.isDirectPlay()) {
                    mVideoEventReporter.onEvent(this.isFromFeed ? "feed_break" : "detail_break");
                }
            } else {
                mVideoEventReporter.onEvent(this.isFromFeed ? "feed_break" : "detail_break");
            }
        }

        JSONObject jsonObject = new JSONObject();
        try {
            if (mStartPlayTs > 0) {
                mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                mStartPlayTs = 0;
            }
            jsonObject.put("duration", mTotalPlayTime - mSmallPlayTime);
            jsonObject.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
            jsonObject.put("small_play_time", mSmallPlayTime);
            jsonObject.put("log_extra", mLogExtra);
            if (mArticle != null && mArticle.videoSubjectId > 0) {
                jsonObject.put("video_subject_id", mArticle.videoSubjectId);
            }
        } catch (Exception exception) {
        }

        if (!this.j && mAdId > 0 && !android.support.design.a.isTextEmpty(mVideoId)) {
            if (arg21) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(),
                        "embeded_ad", isFromFeed ? "feed_skip" : "detail_skip",
                        mAdId,
                        0,
                        jsonObject, 0);
            }

            if (this.isPatchVideo()) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", isFromFeed ? "patch_feed_break" : "patch_detail_break", mAdId, 0, jsonObject, 0);
            } else {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", isFromFeed ? "feed_break" : "detail_break", mAdId, 0, jsonObject, 0);
            }
        }

        if (!this.j && mArticle != null) {
            try {
                jsonObject.put("position", this.isFromFeed ? "list" : "detail");
                jsonObject.put("item_id", mArticle.itemId);
                jsonObject.put("aggr_type", mArticle.aggrType);
                if (mArticle != null && mArticle.videoSubjectId > 0) {
                    jsonObject.put("video_subject_id", mArticle.videoSubjectId);
                }
                this.appendClarityArgs(jsonObject);
            } catch (JSONException jsonException) {
            }

            if ((this.isDirectPlay) && (this.isFromFeed)) {
                JSONObject jo = new JSONObject();
                try {
                    jo.put("duration", mTotalPlayTime);
                    jo.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                    jo.put("log_extra", mLogExtra);
                    jo.put("position", this.isFromFeed ? "list" : "detail");
                    if (mArticle != null) {
                        jo.put("item_id", mArticle.itemId);
                        if (mArticle.videoSubjectId > 0) {
                            jo.put("video_subject_id", mArticle.videoSubjectId);
                        }
                    }
                    this.appendClarityArgs(jo);
                } catch (JSONException jsonException) {
                }

                if (mAdId > 0) {
                    MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "feed_auto_over", mAdId, 0, jo, 0);
                } else {
                    MobClickCombiner.onEvent(BaseApplication.getApplication(), "video_over", "feed_auto_over", mArticle.groupId, 0, jo);
                }

                if (this.ar) {
                    this.onEvent("video_over", jsonObject);
                }
            } else if (!this.j()) {
                this.onEvent("video_over", jsonObject);
            } else if (!this.isFromFeed && mVideoAutoPlayHelperDetail != null) {
                Context context;
                if (mRefContext == null) {
                    context = null;
                } else {
                    context = mRefContext.get();
                }
                mVideoAutoPlayHelperDetail.onEvent(context, this.getCategoryLabel("click"), mArticle.groupId, mAdId, jsonObject);
            }
        }
        mTotalPlayTime = 0;
        mStartPlayTs = 0;
        mCurrentPosition = 0;
        mDuration = 0;
        this.j = false;
        this.isPrepared = false;
        this.isPlayError = false;
        mNewestDragPosition = 0;
        this.K = false;
        mLastVideoPos = -1;
        mVideoHeight = 0;
        mVideoWidth = 0;
        mPatchPosition = -1;
        this.av = false;
        mLastTotalPlayTime = 0;
        mDurationSeconds = 0;
        mAdJumpCountdown = 0;
        mAdId = 0;
        this.av = false;
        this.unregisterConnectivityReceiver();
        this.clearPendingActions();
    }

    public void clearOnCloseListener() {
        mCloseListenerRef = null;
    }

    public void continuePlay(boolean isDirectPlay) {
        this.isSurfaceCreated = false;
        this.ai = false;
        this.isDirectPlay = isDirectPlay;
        this.isPauseFromList = false;
        mMediaLayout.showMediaPlayer(mVideoContainer);
        mMediaLayout.setIsLiveVideo(this.isLiveVideo);
        if (this.isPatchVideo()) {
            mMediaLayout.setIsPatchVideo(true, mAdJumpCountdown == -1);
        }

        if (mRefContext != null
                && mRefContext.get() instanceof FeedTab
                && isDirectPlay
                && mCoverImageIvRef != null) {
            View view = mCoverImageIvRef.get();
            if (view != null) {
                this.setContainerSize(view.getWidth(), view.getHeight());
            }
        }
        mMediaLayout.setSurfaceViewVisible(View.GONE);
        mMediaLayout.setSurfaceViewVisible(View.VISIBLE);
        if (!this.isFromFeed || !this.isDirectPlay()) {
            mMediaLayout.setDirectPlay(false);
            mMediaLayout.dismissToolBar(true, false);
        } else {
            mMediaLayout.setDirectPlay(true);
            mMediaLayout.dismissToolBar(false, false);
        }

        if (mAdId <= 0 || (this.isFromFeed) || (android.support.design.a.isTextEmpty(mExternalUrl)) || (this.isPatchVideo())) {
            mMediaLayout.setAdGoLanding(false);
        } else {
            mMediaLayout.setAdGoLanding(true);
        }
        mMediaLayout.dismissLoading();
        mMediaLayout.setPlayerSurfaceViewSize(!this.av);
        this.syncPosition(true);
        if (!this.pendingPausedVideo) {
            this.executeOrPendingAction(new Runnable() {
                public final void run() {
                    VideoController.this.a(false);
                    VideoController.this.requestPositionDelay();
                }
            });
        } else {
            mMediaLayout.disableAutoRotate();
            if (mArticle != null) {
                mMediaLayout.showCover(mArticle.largeImageList, false);
            }
        }
    }

    private void releaseMedia(boolean arg21) {
        VideoCacheManager.getInstance().cancelPreDownload();
        if (mMediaLayout != null) {
            mMediaLayout.setKeepScreenOn(false);
            mMediaLayout.disableAutoRotate();
        }

        if ((this.nonNullContext()) && (arg21 || !this.isFromFeed || !this.R)) {
            Logger.d("VideoController", "releaseMedia");
            if (mGetPlayUrlThread != null) {
                mGetPlayUrlThread.cancelRequest();
            }

            if (mUsingMediaPlayer != null) {
                if (!this.j && (TextUtils.equals(mVideoId, VideoPref.getLastVideoId()))) {
                    long currentPlayPosition = this.getCurrentPlayPosition();
                    if (currentPlayPosition > 0) {
                        VideoPref.setLastVideoPos(currentPlayPosition);
                    }
                }
                mUsingMediaPlayer.release();
            }

            if (!this.isFromFeed
                    && !this.isLiveVideo
                    && !this.o()
                    && mVideoAutoPlayHelperDetail != null
                    && mVideoAutoPlayHelperDetail.a(this.isFullscreen, this.isAd(), mThirdVideoPartnerData)
                    && this.isFullscreen) {
                VideoAutoPlayHelperDetail.dismissVolumeOrTouchView(mMediaLayout);
            } else if (mMediaLayout != null) {
                mMediaLayout.dismissNoWifiNoticeDialog();
                if (this.isFullscreen) {
                    this.isFullscreen = !this.isFullscreen;
                    mMediaLayout.exitFullScreen(mVideoContainer);
                    this.requestOrienation(1);
                    IVideoFullscreen videoFullscreen = mVideoFullscreenRef != null ? mVideoFullscreenRef.get() : null;
                    if (videoFullscreen != null) {
                        videoFullscreen.onFullscreenChanged(this.isFullscreen);
                    }
                }
                mMediaLayout.releaseMediaPlayer();
            }

            this.removeRequestPositionRunnable();
            mWeakHandler.removeCallbacks(this.RetryPlayRunnable);
            if (mCoverImageIvRef != null) {
                mCoverImageIvRef.clear();
            }

            if (mVideoContainerRef != null) {
                View view = mVideoContainerRef.get();
                if (view != null && view instanceof RelativeLayout) {
                    ((RelativeLayout) view).removeAllViews();
                    view.setVisibility(View.GONE);
                }
                mVideoContainerRef.clear();
            }

            this.mBindedTag = null;
            if (mVideoStatistics != null && !android.support.design.a.isTextEmpty(mVideoId)) {
                mVideoStatistics.a(this.j);
            }

            if (!this.isSplashVideoPlaying) {
                if (!this.j && !android.support.design.a.isTextEmpty(mVideoId)) {
                    String v2_3;
                    if (this.isFromFeed) {
                        if (!this.isDirectPlay()) {
                            VideoEventReporter v3 = mVideoEventReporter;
                            v2_3 = this.isFromFeed ? "feed_break" : "detail_break";
                            v3.onEvent(v2_3);
                        }
                    } else {
                        VideoEventReporter v3 = mVideoEventReporter;
                        v2_3 = this.isFromFeed ? "feed_break" : "detail_break";
                        v3.onEvent(v2_3);
                    }
                }
                JSONObject jsonObject = new JSONObject();
                try {
                    if (mStartPlayTs > 0) {
                        mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                        mStartPlayTs = 0;
                    }

                    jsonObject.put("duration", mTotalPlayTime - mSmallPlayTime);
                    jsonObject.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                    jsonObject.put("small_play_time", mSmallPlayTime);
                    jsonObject.put("log_extra", mLogExtra);
                    if (mArticle != null && mArticle.videoSubjectId > 0) {
                        jsonObject.put("video_subject_id", mArticle.videoSubjectId);
                    }
                } catch (Exception exception) {
                }
                if (!this.j && mAdId > 0 && !android.support.design.a.isTextEmpty(mVideoId)) {
                    if (this.isFromFeed) {
                        if (!this.isFromFeed) {
                        } else if (!this.isDirectPlay()) {
                            if (this.isPatchVideo()) {
                                Application application = BaseApplication.getApplication();
                                MobAdClickCombiner.onAdEvent(application,
                                        "embeded_ad", this.isFromFeed ? "patch_feed_break" : "patch_detail_break",
                                        mAdId,
                                        0,
                                        jsonObject,
                                        0);
                            } else {
                                Application application = BaseApplication.getApplication();
                                MobAdClickCombiner.onAdEvent(application,
                                        "embeded_ad",
                                        this.isFromFeed ? "feed_break" : "detail_break",
                                        mAdId,
                                        0,
                                        jsonObject,
                                        0);
                            }
                        }
                    } else {
                        if (this.isPatchVideo()) {
                            Application application = BaseApplication.getApplication();
                            MobAdClickCombiner.onAdEvent(application,
                                    "embeded_ad", this.isFromFeed ? "patch_feed_break" : "patch_detail_break",
                                    mAdId,
                                    0,
                                    jsonObject,
                                    0);
                        } else {
                            Application application = BaseApplication.getApplication();
                            MobAdClickCombiner.onAdEvent(application,
                                    "embeded_ad",
                                    this.isFromFeed ? "feed_break" : "detail_break",
                                    mAdId,
                                    0,
                                    jsonObject,
                                    0);
                        }
                    }
                }

                if (this.j) {
                } else if (mArticle == null) {
                } else {
                    try {
                        jsonObject.put("position", this.isFromFeed ? "list" : "detail");
                        jsonObject.put("item_id", mArticle.itemId);
                        jsonObject.put("aggr_type", mArticle.aggrType);
                        if (mArticle.videoSubjectId > 0) {
                            jsonObject.put("video_subject_id", mArticle.videoSubjectId);
                        }
                        this.appendClarityArgs(jsonObject);
                    } catch (JSONException jsonException) {
                    }

                    Context v4_1;
                    if ((this.isDirectPlay) && (this.isFromFeed)) {
                        JSONObject jo = new JSONObject();
                        try {
                            jo.put("duration", mTotalPlayTime);
                            jo.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                            jo.put("log_extra", mLogExtra);
                            jo.put("position", this.isFromFeed ? "list" : "detail");
                            jo.put("item_id", mArticle.itemId);
                            if (mArticle.videoSubjectId > 0) {
                                jo.put("video_subject_id", mArticle.videoSubjectId);
                            }
                            this.appendClarityArgs(jo);
                        } catch (JSONException jsonException) {
                        }

                        if (mAdId > 0) {
                            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "feed_auto_over", mAdId, 0, jo, 2);
                        } else if (!this.j()) {
                            MobClickCombiner.onEvent(BaseApplication.getApplication(), "video_over", "feed_auto_over", mArticle.groupId, 0, jo);
                        } else if (!this.isFromFeed && mVideoAutoPlayHelperDetail != null) {
                            if (mRefContext == null) {
                                v4_1 = null;
                            } else {
                                v4_1 = (Context) mRefContext.get();
                            }

                            mVideoAutoPlayHelperDetail.onEvent(v4_1, this.getCategoryLabel("click"), mArticle.groupId, mAdId, jsonObject);
                        }

                        if (this.ar) {
                            this.onEvent("video_over", jsonObject);
                        }
                    } else if (!this.j()) {
                        this.onEvent("video_over", jsonObject);
                    } else if (!this.isFromFeed && mVideoAutoPlayHelperDetail != null) {
                        Context context;
                        if (mRefContext == null) {
                            context = null;
                        } else {
                            context = mRefContext.get();
                        }
                        mVideoAutoPlayHelperDetail.onEvent(context, this.getCategoryLabel("click"), mArticle.groupId, mAdId, jsonObject);
                    }
                }
            }
            ICloseListener closeListener = mCloseListenerRef != null ? mCloseListenerRef.get() : null;
            if (!this.isFromFeed && closeListener != null && this.isExitintActivity) {
                this.isExitintActivity = false;
                closeListener.onClose(true);
            }
            this.isDirectPlay = false;
            this.ar = false;
            mExternalUrl = null;
            mCategoryName = null;
            mTotalPlayTime = 0;
            mStartPlayTs = 0;
            mCurrentPosition = 0;
            mDuration = 0;
            this.j = false;
            this.isPrepared = false;
            this.isPlayError = false;
            mNewestDragPosition = 0;
            mVideoSource = null;
            mRetryCount = 0;
            this.K = false;
            mLastVideoPos = -1;
            mVideoHeight = 0;
            mVideoWidth = 0;
            mVideoId = null;
            this.isExitintActivity = false;
            mSmallPlayTime = 0;
            mPatchPosition = -1;
            mArticle = null;
            mRefThirdPartnerListner = null;
            mThirdVideoPartnerData = null;
            this.isSurfaceCreated = false;
            this.av = false;
            mLastTotalPlayTime = 0;
            mDurationSeconds = 0;
            mAdJumpCountdown = 0;
            this.isPendingPlay = false;
            this.isSplashVideoPlaying = false;
            this.isLiveVideo = false;
            mVideoDataContainer = null;
            this.aU = 0;
            mLoop = 0;
            this.unregisterConnectivityReceiver();
            this.clearPendingActions();
            this.abandonAudioFocus();
            if (mMediaLayout != null) {
                mMediaLayout.clearView();
            }

            this.shouldPreloadVideo = false;
            mClarityActual = "";
        }
    }

    final void requestPositionDelay() {
        this.removeRequestPositionRunnable();
        mWeakHandler.postDelayed(mRequestPositionRunnable, 800L);
    }

    public void dismiss(boolean arg5) {
        Logger.d("VideoController", "dismiss");
        if ((arg5) || !this.R) {
            if (mCoverImageIvRef != null) {
                mCoverImageIvRef.clear();
            }

            if (!this.isPauseFromList() || !this.isPatchVideo()) {
                mMediaLayout.setVisibility(View.INVISIBLE);
            }

            int v0 = System.currentTimeMillis() - this.S < 2000 ? 1 : 0;
            if (v0 != 0) {
                return;
            }

            if (this.isFullscreen) {
                return;
            }

            if (this.isPauseFromList() && this.isPatchVideo()) {
                return;
            }

            this.releaseMedia(arg5);
        }
    }

    final void removeRequestPositionRunnable() {
        mWeakHandler.removeCallbacks(mRequestPositionRunnable);
    }

    private boolean playAdUrl(boolean before) {
        if (hasAdPatch()) {
            int patchPosition = before ? PATCH_POSITION_BEFORE : PATCH_POSITION_AFTER;
            mMediaLayout.handleBtnAdShowOrHide(Boolean.FALSE);
            for (int i = 0; i < mVideoDataContainer.mVideoAdInfoList.size(); ++i) {
                VideoAdInfo videoAdInfo = mVideoDataContainer.mVideoAdInfoList.get(i);
                if (videoAdInfo != null && videoAdInfo.patchPosition == patchPosition && videoAdInfo.mVideoItem1 != null) {
                    mMediaLayout.setVideoSize(videoAdInfo.mVideoItem1.videoWidth, videoAdInfo.mVideoItem1.videoHeight);
                    mVideoWidth = videoAdInfo.mVideoItem1.videoWidth;
                    mVideoHeight = videoAdInfo.mVideoItem1.videoHeight;
                    mPatchPosition = patchPosition;
                    this.av = true;
                    mAdId = videoAdInfo.id;
                    mLogExtra = videoAdInfo.logExtra;
                    mExternalUrl = videoAdInfo.externalUrl;
                    mAdJumpCountdown = videoAdInfo.skipTime;
                    mMediaLayout.setIsPatchVideo(true, mAdJumpCountdown == -1);
                    mMediaLayout.updateAdLeftTime(videoAdInfo.duration, mAdJumpCountdown);
                    if (mUsingMediaPlayer != null) {
                        if (mAbandonMediaPalyer != null) {
                            mAbandonMediaPalyer.onDestroy();
                        }
                        mAbandonMediaPalyer = mUsingMediaPlayer;
                        mUsingMediaPlayer.onRelease();
                    }
                    mWeakHandler = new WeakHandler(this);
                    mUsingMediaPlayer = new SSMediaPlayerWrapper(mWeakHandler, false);
                    mTotalPlayTime = 0L;
                    this.isPlayError = false;
                    mReportJO = new JSONObject();
                    try {
                        if (!android.support.design.a.isTextEmpty(mLogExtra)) {
                            mReportJO.put("log_extra", mLogExtra);
                        }
                    } catch (JSONException jsonException) {
                    }
                    AbsApplication application = BaseApplication.getApplication();
                    MobAdClickCombiner.onAdEvent(application, "embeded_ad", "show", mAdId, 0L, mReportJO, 0);
                    MobAdClickCombiner.onAdEvent(application, "embeded_ad",
                            this.isFromFeed ? "feed_play" : "detail_play", mAdId, 0L, mReportJO, 0);
                    AppUtil.a(videoAdInfo.playTrackUrlList, BaseApplication.getApplication());
                    this.shouldPreloadVideo = false;
                    if (mVideoStatistics != null) {
                        VideoStatistics videoStatistics = mVideoStatistics;
                        videoStatistics.appendType(before ? 196608 : 196609);
                    }
                    this.startPlayVideo(MediaHelper.getVideoSource(videoAdInfo.mVideoItem1.mainUrl));
                    return true;
                }
            }
            return false;
        } else {
            return false;
        }
    }

    final void f() {
        if (mVideoDataContainer != null
                && mVideoDataContainer.mVideoInfo != null) {
            mMediaLayout.handleBtnAdShowOrHide(Boolean.valueOf(true));
            VideoInfo videoInfo = mVideoDataContainer.mVideoInfo;
            VideoItem videoItem = getVideoItemByClarity(videoInfo);
            if (videoItem != null) {
                mMediaLayout.restoreClaritySelectByCache(VideoClarityHelper.getDefinitionStr(videoItem.definition), VideoClarityHelper.getSupportVideoInfos(videoInfo));
                mMediaLayout.setSelectClarityItem(videoItem, null);
                mMediaLayout.setVideoSize(videoItem.videoWidth, videoItem.videoHeight);
                mVideoWidth = videoItem.videoWidth;
                mVideoHeight = videoItem.videoHeight;
                mPatchPosition = PATCH_POSITION_MIDDLE;
                mMediaLayout.setIsPatchVideo(false, false);
                if (mUsingMediaPlayer != null) {
                    if (mAbandonMediaPalyer != null) {
                        mAbandonMediaPalyer.onDestroy();
                    }
                    mAbandonMediaPalyer = mUsingMediaPlayer;
                    mAbandonMediaPalyer.onRelease();
                }

                mWeakHandler = new WeakHandler(this);
                mUsingMediaPlayer = new SSMediaPlayerWrapper(mWeakHandler, false);
                mTotalPlayTime = 0L;
                this.isPlayError = false;
                if ((AppData.getInstance().hasVideoKeepPos()) && TextUtils.equals(videoInfo.videoId, VideoPref.getLastVideoId())) {
                    mLastVideoPos = VideoPref.getLastVideoPos();
                }

                if (mVideoStatistics != null) {
                    mVideoStatistics.appendParam("ad_exist", hasAdPatch() ? 1L : 0L);
                    mVideoStatistics.appendType(isAd() ? 65537 : 65536);
                }
                this.startPlayVideo(MediaHelper.getVideoSource(videoItem.mainUrl));
            }
        }
    }

    private void init() {
        this.isJellyBeanMR1 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
        mUsingMediaPlayer = new SSMediaPlayerWrapper(mWeakHandler, false);
        mVideoEventReporter = new VideoEventReporter(BizApplication.getApplication());
    }

    public Object getBindedTag() {
        return this.isFullscreen ? null : this.mBindedTag;
    }

    public void setBindedTag(Object bindedTag) {
        this.mBindedTag = bindedTag;
    }

    public String getCategory() {
        return mCategoryName;
    }

    public String getCategoryLabel(String arg3) {
        if ((!this.isFromFeed) && (!android.support.design.a.isTextEmpty(this.ag))) {
            if ("click_related".equals(this.ag)
                    || "click_album".equals(this.ag)
                    || "click_search".equals(this.ag)
                    || "click_pgc".equals(this.ag)
                    || "click_subject".equals(this.ag)
                    || "click_favorite".equals(this.ag)) {
                return this.ag;
            }
        }
        if ("__all__".equals(mCategoryName)) {
            return arg3 + "_headline";
        }

        if (android.support.design.a.isTextEmpty(mCategoryName)) {
            return arg3;
        }
        arg3 = arg3 + "_" + mCategoryName;
        return arg3;
    }

    public int getContainerHeight() {
        return mMediaLayout == null ? 0 : mMediaLayout.getContainerHeight();
    }

    public Context getContext() {
        if (!this.nonNullContext()) {
            return null;
        } else {
            return mRefContext.get();
        }
    }

    public String getCurrentLabel() {
        return null;
    }

    public long getCurrentPlayPosition() {
        return this.isVideoPlaying() || this.isVideoPaused() ? mCurrentPosition : -1;
    }

    public DetailPageListener getDetailPageListener() {
        DetailPageListener detailPageListener;
        if (mDetailPageListener != null) {
            detailPageListener = mDetailPageListener.get();
        } else {
            detailPageListener = null;
        }
        return detailPageListener;
    }

    public void setDetailPageListener(DetailPageListener detailPageListener) {
        mDetailPageListener = new WeakReference(detailPageListener);
        if (mVideoAutoPlayHelperDetail != null) {
            mVideoAutoPlayHelperDetail.setDetailPageListener(detailPageListener);
        }
    }

    public long getGroupId() {
        return mArticle != null ? mArticle.groupId : 0;
    }

    public IMediaLayout getMediaViewLayout() {
        return mMediaLayout;
    }

    public int getPct() {
        return MediaHelper.timeToPercent(mCurrentPosition, mDuration);
    }

    public VideoAutoPlayHelperDetail getVideoAutoPlayHelperDetail() {
        return mVideoAutoPlayHelperDetail;
    }

    public String getVideoId() {
        return mVideoId;
    }

    private void registerConnectivityReceiver() {
        if (!this.isReceiverRegistered) {
            AbsApplication application = BaseApplication.getApplication();
            this.isReceiverRegistered = true;
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
            try {
                application.registerReceiver(mBroadcastReceiver, intentFilter);
            } catch (Exception exception) {
            }
        }
    }

    public void handleAdGoLandingClick(boolean arg12) {
        String v3;
        String v2;
        AbsApplication v1;
        AbsApplication v0_1 = null;
        String v10 = null;
        long v6 = 0;
        Object v0 = mRefContext != null ? mRefContext.get() : v10;
        if (v0 == null) {
            v0_1 = BaseApplication.getApplication();
        }

        if (!android.support.design.a.isTextEmpty(mExternalUrl)) {
            if (mAdId > v6) {
                if (this.isPatchVideo()) {
                    if (arg12) {
                        v1 = BaseApplication.getApplication();
                        v2 = "embeded_ad";
                        v3 = this.isFromFeed ? "feed_click_landingpage" : "detail_click_landingpage";
                        MobAdClickCombiner.onAdEvent(((Context) v1), v2, v3, mAdId, v6, mReportJO, 0);
                    } else {
                        v1 = BaseApplication.getApplication();
                        v2 = "embeded_ad";
                        v3 = this.isFromFeed ? "feed_click" : "detail_click";
                        MobAdClickCombiner.onAdEvent(((Context) v1), v2, v3, mAdId, v6, mReportJO, 0);
                    }

                    MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "click", mAdId, v6, mReportJO, 0);
                } else {
                    MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "ad_click", mAdId, v6, mReportJO, 0);
                }

                AppUtil.a(mExternalUrl, BaseApplication.getApplication());
            }

            this.aB = true;
            AdsAppActivity.openUrl(v0_1, mExternalUrl, v10);
        }
    }

    public void handleAdJumpClick() {
        if (mAdJumpCountdown <= 0) {
            if (mPatchPosition == 1) {
                this.c(true);
                this.f();
            } else if (mPatchPosition == 2) {
                this.c(true);
            }
        }
    }

    public void handleBackClick(IMediaLayout mediaLayout, View view) {
        if (this.isFullscreen) {
            this.isFullscreen = !this.isFullscreen;
            mMediaLayout.exitFullScreen(mVideoContainer);
            this.requestOrienation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {
            this.isExitintActivity = true;
            this.isActivityOnDestroy = true;
            this.releaseMedia();
        }
    }

    public void handleClarityChange() {
        if (mVideoDataContainer != null && mVideoDataContainer.mVideoInfo != null) {
            mClarityChangeTime = mCurrentPosition;
            VideoItem videoItem = mMediaLayout.getSelectClarity();
            if (videoItem != null) {
                mClarityActual = videoItem.definition;
                String videoSource = maybeProxyUrl(MediaHelper.getVideoSource(videoItem.mainUrl));
                if (!android.support.design.a.isTextEmpty(videoSource)) {
                    mVideoSource = videoSource;
                    if (mUsingMediaPlayer != null) {
                        mUsingMediaPlayer.release();
                        if (mAbandonMediaPalyer != null) {
                            mAbandonMediaPalyer.onDestroy();
                        }

                        mAbandonMediaPalyer = mUsingMediaPlayer;
                        mUsingMediaPlayer.onRelease();
                    }

                    mWeakHandler = new WeakHandler(this);
                    mUsingMediaPlayer = new SSMediaPlayerWrapper(mWeakHandler, false);
                    mUsingMediaPlayer.setDataSource(videoSource);
                    mLastVideoPos = TextUtils.equals(mVideoId, VideoPref.getLastVideoId()) ? VideoPref.getLastVideoPos() : -1;
                    this.isSurfaceCreated = false;
                    this.ai = false;
                    mMediaLayout.setSurfaceViewVisible(8);
                    mMediaLayout.setSurfaceViewVisible(0);
                    mMediaLayout.setPlayIcon(false, this.isLiveVideo);
                    mMediaLayout.dismissCover();
                    mMediaLayout.showLoading();
                    this.executeOrPendingAction(new Runnable() {

                        public final void run() {
                            VideoController.this.a(true);
                            VideoController.this.requestPositionDelay();
                        }
                    });
                }
            }
        }
    }

    public void handleCloseClick(IMediaLayout mediaLayout, View view) {
        if (!this.isFromFeed) {
            mVideoEventReporter.onEvent("detail_video_close_button");
        }
        mMediaLayout.releaseMediaPlayer();
        this.releaseMedia();
        this.notifyOnClose();
    }

    public void handleFullScreenBackClick(IMediaLayout mediaLayout, View view) {
        this.handleFullScreenBackClick(mediaLayout, view, false);
    }

    public void handleFullScreenBackClick(IMediaLayout mediaLayout, View view, boolean fromGravitySensor) {
        if (this.nonNullContext()) {
            this.isFullscreen = !this.isFullscreen;
            DetailPageListener detailPageListener = mDetailPageListener != null ? mDetailPageListener.get() : null;
            if (!this.isFromFeed && detailPageListener != null) {
                detailPageListener.onFullscreenChanged(this.isFullscreen);
            }
            if (!(mRefContext.get() instanceof Activity)) {
                Logger.d("VideoController", "context is not activity, not support this function.");
                return;
            }

            if (mMediaLayout != null) {
                mMediaLayout.exitFullScreen(mVideoContainer);
                mMediaLayout.trySetTitleVisiable(this.isFromFeed && this.j);
            }

            this.requestOrienation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            IVideoFullscreen videoFullscreen = mVideoFullscreenRef != null ? mVideoFullscreenRef.get() : null;
            if (videoFullscreen != null) {
                videoFullscreen.onFullscreenChanged(this.isFullscreen);
            }

            if (mArticle != null) {
                JSONObject jsonObject = new JSONObject();
                try {
                    jsonObject.put("item_id", mArticle.itemId);
                    jsonObject.put("aggr_type", mArticle.aggrType);
                } catch (JSONException jsonException) {
                }

                if (fromGravitySensor) {
                    MobClickCombiner.onEvent(BaseApplication.getApplication(),
                            "video",
                            isFromFeed ? "feed_fullscreen_exit_gravity_sensing" : "detail_fullscreen_exit_gravity_sensing",
                            mArticle.groupId,
                            mAdId,
                            jsonObject);
                } else {
                    MobClickCombiner.onEvent(BaseApplication.getApplication(),
                            "video", isFromFeed ? "feed_fullscreen_exit_back_button" : "detail_fullscreen_exit_back_button",
                            mArticle.groupId,
                            mAdId,
                            jsonObject);
                }
            }
            if (mVideoAutoPlayHelperDetail != null) {
                Context context;
                if (mRefContext != null) {
                    context = mRefContext.get();
                } else {
                    context = null;
                }
                mVideoAutoPlayHelperDetail.reportFullscreenChanged(context, this.isFullscreen);
            }
        }
    }

    public void handleFullScreenClick(IMediaLayout mediaLayout, View view) {
        this.handleFullScreenClick(mediaLayout, view, false, false);
    }

    public void handleFullScreenClick(IMediaLayout mediaLayout, View view, boolean isReverseLandscape, boolean fromGravitySensor) {
        if (this.nonNullContext()) {
            this.isFullscreen = !this.isFullscreen;
            if (view != null && view.getId() == com.ss.android.article.browser.R.id.video_full_screen) {
                this.Y = true;
            }

            if (!(mRefContext.get() instanceof Activity)) {
                Logger.d("VideoController", "context is not activity, not support this function.");
                return;
            }

            if (this.isFullscreen) {
                mMediaLayout.enterFullScreen(mVideoContainer);
                mMediaLayout.trySetTitleVisiable(false);
                int orientation = isReverseLandscape ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
                this.requestOrienation(orientation);
                if (fromGravitySensor) {
                    mVideoEventReporter.onEvent(isFromFeed ? "feed_fullscreen_gravity_sensing" : "detail_fullscreen_gravity_sensing");
                } else {
                    mVideoEventReporter.onEvent(isFromFeed ? "feed_fullscreen" : "detail_fullscreen");
                }
            } else {
                mMediaLayout.exitFullScreen(mVideoContainer);
                mMediaLayout.trySetTitleVisiable(isFromFeed && this.j);
                this.requestOrienation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                if (fromGravitySensor) {
                    mVideoEventReporter.onEvent(isFromFeed ? "feed_fullscreen_exit_gravity_sensing" : "detail_fullscreen_exit_gravity_sensing");
                } else {
                    mVideoEventReporter.onEvent(isFromFeed ? "feed_fullscreen_exit_normal" : "detail_fullscreen_exit_normal");
                }
            }
            IVideoFullscreen videoFullscreen = mVideoFullscreenRef != null ? mVideoFullscreenRef.get() : null;
            if (videoFullscreen != null) {
                videoFullscreen.onFullscreenChanged(this.isFullscreen);
            }

            if (!this.isFullscreen) {
                return;
            }

            if (mAdId > 0L) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(),
                        "embeded_ad",
                        isFromFeed ? "feed_fullscreen" : "detail_fullscreen",
                        mAdId,
                        0L, mReportJO, 0);
            }
        }
    }

    public void handleFullScreenMoreClick(IMediaLayout mediaLayout, View view) {
        if (mShareListenerRef != null) {
            IShareListener shareListener = mShareListenerRef.get();
            if (shareListener != null) {
                shareListener.onFullScreenMoreClick();
            }
        }
    }

    public void handleItemShareClick(int channel) {
        if (mPlayCompleteListenerRef != null) {
            IPlayCompleteListener playCompleteListener = mPlayCompleteListenerRef.get();
            if (playCompleteListener != null) {
                playCompleteListener.onItemShare(channel);
            }
        }
    }

    public void handleMsg(Message message) {
        if (!this.nonNullContext()) {
            return;
        }

        Context context = mRefContext.get();
        if (mMediaLayout == null) {
            return;
        }

        if (message == null) {
            return;
        }

        if (android.support.design.a.t(context)) {
            return;
        }

        int v1_6;
        JSONObject v8_1;
        long v4_1;
        AbsApplication absApplication;
        boolean v0_3;
        switch (message.what) {
            case 10: {
                View view = mCoverImageIvRef != null ? mCoverImageIvRef.get() : null;
                int v0_2 = !android.support.design.a.u() || view != null || !this.isFromFeed || (this.isPauseFromList()) ? 1 : 0;
                if (v0_2 == 0) {
                    return;
                }

                Bundle data = message.getData();
                if (!android.support.design.a.isTextEmpty(data.getString("video_id"))) {
                    if (mVideoStatistics != null) {
                        mVideoStatistics.c("at");
                    }
                    if (message.obj instanceof VideoDataContainer) {
                        mVideoDataContainer = (VideoDataContainer) message.obj;
                        if (this.isLiveVideo) {
                            Context ctx = mRefContext.get();
                            if (((ctx instanceof IComponent)) && (this.isLiveVideo) && !((IComponent) ctx).isDestroyed()) {
                                if (mVideoDataContainer != null && mVideoDataContainer.mLiveInfo != null && (mVideoDataContainer.mLiveInfo.mLiveItem0 != null || mVideoDataContainer.mLiveInfo.mLiveItem1 != null)) {
                                    if (mVideoDataContainer.mLiveInfo.liveStatus == 2) {
                                        String errortxt = ctx.getResources().getString(com.ss.android.article.browser.R.string.live_video_error_wait);
                                        mMediaLayout.showLiveError(errortxt, !this.isFromFeed);
                                        MobClickCombiner.onEvent(BaseApplication.getApplication(), "live", "waiting", mArticle != null ? mArticle.groupId : 0, 0);
                                    } else if (mVideoDataContainer.mLiveInfo.liveStatus == 0) {
                                        String errorTxt = ctx.getResources().getString(com.ss.android.article.browser.R.string.live_video_error_unknow);
                                        mMediaLayout.showLiveError(errorTxt, !this.isFromFeed);
                                        MobClickCombiner.onEvent(BaseApplication.getApplication(),
                                                "live",
                                                "loadingfail", mArticle != null ? mArticle.groupId : 0, 0);
                                    } else if (mVideoDataContainer.mLiveInfo.liveStatus == 1) {
                                        String errorTxt = ctx.getResources().getString(com.ss.android.article.browser.R.string.live_video_error_end);
                                        mMediaLayout.showLiveError(errorTxt, !this.isFromFeed);
                                        MobClickCombiner.onEvent(BaseApplication.getApplication(),
                                                "live",
                                                "over", mArticle != null ? mArticle.groupId : 0, 0);
                                    } else {
                                        LiveItem liveItem = mVideoDataContainer.mLiveInfo.mLiveItem0 != null
                                                ? mVideoDataContainer.mLiveInfo.mLiveItem0
                                                : mVideoDataContainer.mLiveInfo.mLiveItem1;
                                        mMediaLayout.setVideoSize(mVideoWidth, mVideoHeight);
                                        mMediaLayout.setIsLiveVideo(true);
                                        mPatchPosition = 3;
                                        if (mUsingMediaPlayer != null) {
                                            if (mAbandonMediaPalyer != null) {
                                                mAbandonMediaPalyer.onDestroy();
                                            }

                                            mAbandonMediaPalyer = mUsingMediaPlayer;
                                            mUsingMediaPlayer.onRelease();
                                        }
                                        mWeakHandler = new WeakHandler(this);
                                        mUsingMediaPlayer = new SSMediaPlayerWrapper(mWeakHandler);
                                        mTotalPlayTime = 0;
                                        this.isPlayError = false;
                                        if (mVideoStatistics != null) {
                                            mVideoStatistics.appendType(131072);
                                        }
                                        this.shouldPreloadVideo = false;
                                        this.startPlayVideo(liveItem.mainPlayUrl);
                                    }
                                } else {
                                    String errorTxt = ctx.getResources().getString(com.ss.android.article.browser.R.string.live_video_error_unknow);
                                    mMediaLayout.showLiveError(errorTxt, !this.isFromFeed);
                                }
                            }
                        }
                        if (this.playAdUrl(true)) {

                        } else if (mVideoDataContainer.mVideoInfo == null) {

                        } else {
                            this.f();
                        }
                    }
                }
                String error1 = data.getString("error1");
                String data_error1 = data.getString("data_error1");
                String url = data.getString("url");
                if (mVideoStatistics == null) {
                    return;
                }
                if (TextUtils.isEmpty(error1) && TextUtils.isEmpty(data_error1)) {
                    return;
                }
                mVideoStatistics.appendParams(url, error1, "", data_error1, "");
                return;
            }
            case 11: {
                Bundle v1 = message.getData();
                String v2 = v1.getString("error1");
                String v3 = v1.getString("error2");
                String v4 = v1.getString("data_error1");
                String v5 = v1.getString("data_error2");
                if (("time out".equals(v2)) || ("time out".equals(v3))) {
                    UIUtils.showImageToast(context, context.getString(com.ss.android.article.browser.R.string.video_fetch_url_fail) + -981);
                } else {
                    if (!"api fail".equals(v2) && !"api fail".equals(v3)) {
                        if (!"empty response".equals(v2) && !"empty response".equals(v3)) {
                            UIUtils.showImageToast(context, context.getString(com.ss.android.article.browser.R.string.video_fetch_url_fail) + -978);
                        } else {
                            UIUtils.showImageToast(context, context.getString(com.ss.android.article.browser.R.string.video_fetch_url_fail) + -979);
                        }
                    } else {
                        UIUtils.showImageToast(context, context.getString(com.ss.android.article.browser.R.string.video_fetch_url_fail) + -980);
                    }
                }
                String url = v1.getString("url");
                mMediaLayout.dismissLoading();
                mMediaLayout.showRetry();
                if (mVideoStatistics != null) {
                    mVideoStatistics.a();
                    mVideoStatistics.appendParams(url, v2, v3, v4, v5);
                    mVideoStatistics.unregisterConnectivityReceiver();
                }

                VideoDiagnosis.a(mVideoId);
                return;
            }
            case OP_REQUEST_DURATION: {
                if (message.obj instanceof Long) {
                    mDuration = (Long) message.obj;
                    this.refreshTimeUI(mCurrentPosition, mDuration);
                    return;
                } else {
                    return;
                }
            }
            case OP_REQUEST_CUR_POSITION:
                if (message.obj instanceof Long) {
                    long position = (Long) message.obj;
                    mCurrentPosition = position;
                    this.refreshTimeUI(position, mDuration);
                    return;
                } else {
                    return;
                }
            case CALLBACK_ON_BUFFERING_UPDATE:
                if (!this.K && mVideoStatistics != null) {
                    if (!mVideoStatistics.e) {
                        mVideoStatistics.e();
                        v0_3 = true;
                    } else {
                        v0_3 = false;
                    }

                    this.K = v0_3;
                    if (mLoadStartRT > 0 && Build.VERSION.SDK_INT < 17) {
                        v8_1 = new JSONObject();
                        try {
                            v8_1.put("load_time", SystemClock.elapsedRealtime() - mLoadStartRT);
                            v8_1.put("item_id", mArticle != null ? Long.valueOf(mArticle.itemId) : "");
                            v8_1.put("position", this.isFromFeed ? "list" : "detail");
                        } catch (JSONException jsonException) {
                        }
                        mLoadStartRT = 0;
                        MobClickCombiner.onEvent(BizApplication.getApplication(),
                                "go_start_play",
                                this.getCategoryLabel("click"),
                                this.getGroupId(),
                                0, v8_1);
                    }
                }

                if (message.obj instanceof Integer) {
                    int v0_2 = (Integer) message.obj;
                    if (mVideoStatistics != null && v0_2 >= 90) {
                        mVideoStatistics.c("bft");
                    }
                    mMediaLayout.setSeekSecondaryProgress(v0_2);
                    return;
                } else {
                    return;
                }
            case CALLBACK_ON_COMPLETE:
                this.onVideoComplete(message.what);
                return;
            case CALLBACK_ON_ERROR:
                int what = message.arg1;
                int extra = message.arg2;
                mVideoErrorString = "Error: (" + what + "," + extra + ")";
                VideoDiagnosis.callbackOnError(mVideoErrorString);
                Logger.e("VideoController", mVideoErrorString);
                this.isPlayError = true;
                if (mVideoStatistics != null) {
                    mVideoStatistics.appendErrorParam("video_error_what", Integer.valueOf(what));
                    mVideoStatistics.appendErrorParam("video_error_extra", Integer.valueOf(extra));
                    switch (what) {
                        case -3648: {
                            what = 2007;
                            break;
                        }
                        case -1106: {
                            what = 2008;
                            break;
                        }
                        case -1011: {
                            what = 2004;
                            break;
                        }
                        case -1008: {
                            what = 2009;
                            break;
                        }
                        case -1007: {
                            what = 2012;
                            break;
                        }
                        case -1004: {
                            what = 2003;
                            break;
                        }
                        case -110: {
                            what = 2006;
                            break;
                        }
                        case -101: {
                            what = 2005;
                            break;
                        }
                        case -38: {
                            what = 2001;
                            break;
                        }
                        case -19: {
                            what = 2002;
                            break;
                        }
                        case -1: {
                            what = 2010;
                            break;
                        }
                        case 48: {
                            what = 2011;
                            break;
                        }
                        default: {
                            what = 1000;
                            break;
                        }
                    }

                    if (mVideoStatistics.mData != null) {
                        try {
                            if (mVideoStatistics.hasKey("vt")) {
                                what += 5000;
                                mVideoStatistics.mData.put("br", 1);
                            }
                            mVideoStatistics.mData.put("errt", what);
                        } catch (Exception v1_7) {
                        }
                    }
                }

                mMediaLayout.dismissLoading();
                if (mVideoEventReporter != null) {
                    if (this.isFromFeed) {
                        if (this.isFromFeed && !this.isDirectPlay()) {
                            mVideoEventReporter.onEvent(isFromFeed ? "feed_break" : "detail_break");
                        }
                    } else {
                        mVideoEventReporter.onEvent(isFromFeed ? "feed_break" : "detail_break");
                    }
                }

                if (this.isLiveVideo) {
                    String txt = context.getResources().getString(com.ss.android.article.browser.R.string.live_video_error_unknow);
                    mMediaLayout.showLiveError(txt, !this.isFromFeed);
                }

                JSONObject jooo = new JSONObject();
                try {
                    if (mStartPlayTs > 0) {
                        mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                        mStartPlayTs = 0;
                    }

                    if (0 > 0) {
                        this.ak = System.currentTimeMillis();
                        mSmallPlayTime += this.ak;
                    }
                    jooo.put("duration", mTotalPlayTime - mSmallPlayTime);
                    jooo.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                    jooo.put("small_play_time", mSmallPlayTime);
                    jooo.put("log_extra", mLogExtra);
                    if (mArticle == null) {
                    } else if (mArticle.videoSubjectId <= 0) {
                    } else {
                        jooo.put("video_subject_id", mArticle.videoSubjectId);
                    }
                } catch (JSONException jsonException) {
                }

                if (mSplashAdListenerRef != null) {
                    ISplashAdListener splashAdListener = mSplashAdListenerRef.get();
                    if (splashAdListener != null) {
                        splashAdListener.onError(mTotalPlayTime, MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                    }
                }

                if (mAdId > 0) {
                    if (this.isFromFeed) {
                        if (!this.isDirectPlay()) {
                            if (this.isPatchVideo()) {
                                MobAdClickCombiner.onAdEvent(context,
                                        "embeded_ad", isFromFeed ? "patch_feed_break" : "patch_detail_break",
                                        mAdId, 0, jooo, 0);
                            } else {
                                MobAdClickCombiner.onAdEvent(context,
                                        "embeded_ad", isFromFeed ? "feed_break" : "detail_break",
                                        mAdId, 0, jooo, 0);
                            }
                        }
                    } else {
                        if (this.isPatchVideo()) {
                            MobAdClickCombiner.onAdEvent(context,
                                    "embeded_ad", isFromFeed ? "patch_feed_break" : "patch_detail_break", mAdId, 0, jooo, 0);
                        } else {
                            MobAdClickCombiner.onAdEvent(context,
                                    "embeded_ad", isFromFeed ? "feed_break" : "detail_break",
                                    mAdId, 0, jooo, 0);
                        }
                    }
                }

                try {
                    jooo.put("position", isFromFeed ? "list" : "detail");
                    this.appendClarityArgs(jooo);
                } catch (JSONException v1_8) {
                }

                if (mArticle != null) {
                    try {
                        jooo.put("item_id", mArticle.itemId);
                        jooo.put("aggr_type", mArticle.aggrType);
                    } catch (JSONException jsonException) {
                    }

                    if (!this.isFromFeed || (this.isFromFeed) && !this.isDirectPlay()) {
                        if (!this.j()) {
                            this.onEvent(context, "video_over", jooo);
                        } else {
                            if (mRefContext == null) {
                                context = null;
                            } else {
                                context = mRefContext.get();
                            }

                            mVideoAutoPlayHelperDetail.onEvent(context, this.getCategoryLabel("click"), mArticle.groupId, mAdId, jooo);
                        }
                    }
                    if (this.isDirectPlay) {
                        JSONObject j04 = new JSONObject();
                        try {
                            j04.put("duration", mTotalPlayTime);
                            j04.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                            j04.put("log_extra", mLogExtra);
                            j04.put("position", isFromFeed ? "list" : "detail");
                            if (mArticle != null) {
                                j04.put("item_id", mArticle.itemId);
                            }
                            this.appendClarityArgs(j04);
                        } catch (JSONException jsonException) {
                        }

                        String position;
                        if (this.isFromFeed) {
                            position = this.ar ? "feed_back_play_over" : "feed_play_over";
                        } else {
                            position = "auto_detail_play_over";
                        }

                        if (mAdId > 0) {
                            MobAdClickCombiner.onAdEvent(context, "embeded_ad", position, mAdId, 0, j04, 0);
                        } else {
                            MobClickCombiner.onEvent(context, "video_over", position, mArticle != null ? mArticle.groupId : 0, 0, j04);
                        }

                        if (this.ar && isFromFeed) {
                            this.onEvent("video_over", j04);
                        }
                    }
                }
                mTotalPlayTime = 0;
                mSmallPlayTime = 0;
                return;
            case CALLBACK_ON_INFO:
                int info = message.arg1;
                if (info == MediaPlayer.MEDIA_INFO_BUFFERING_START) {//701
                    if (mStartPlayTs > 0) {
                        mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                        mStartPlayTs = 0;
                    }
                    if (this.isLiveVideo) {
                        absApplication = BaseApplication.getApplication();
                        MobClickCombiner.onEvent(absApplication, "live", "loading", mArticle != null ? mArticle.groupId : 0, 0);
                    }
                    mMediaLayout.showLoading();
                } else if (info == MediaPlayer.MEDIA_INFO_BUFFERING_END) {//702
                    if (mStartPlayTs <= 0) {
                        mStartPlayTs = System.currentTimeMillis();
                    }
                    mMediaLayout.dismissLoading();
                    this.requestPositionDelay();
                    mMediaLayout.sendDismissToolBarMsg();
                } else if (!this.isJellyBeanMR1) {
                } else if (info == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
                    if (mStartPlayTs <= 0) {
                        if (this.isSplashVideoPlaying) {
                            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "splash_ad", "play", mAdId, 0, mReportJO, 3);
                            AppUtil.a(this.mTrackUrlList, BaseApplication.getApplication());
                        }
                        mStartPlayTs = System.currentTimeMillis();
                    }
                    mMediaLayout.dismissLoading();
                    mMediaLayout.dismissLoadingCover();
                    this.requestPositionDelay();
                    mMediaLayout.sendDismissToolBarMsg();
                }

                if (mVideoStatistics != null) {
                    boolean v1_5;
                    if (info == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
                        ++mVideoStatistics.d;
                        v1_5 = false;
                    } else if (info == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
                        if (mVideoStatistics.e) {
                            mVideoStatistics.e();
                            v1_5 = true;
                        } else {
                            v1_5 = false;
                        }
                    } else if (!mVideoStatistics.e) {
                        v1_5 = false;
                    } else if (info == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
                        mVideoStatistics.e();
                        v1_5 = true;
                    } else {
                        v1_5 = false;
                    }
                    this.K = v1_5;
                    if (!android.support.design.a.isTest(context)) {
                    } else {
                        v1_6 = AppData.getInstance().mVideoIsShowToast > 0 ? 1 : 0;
                        if (v1_6 == 0) {
                        } else if (this.aI) {
                        } else if (mVideoStatistics == null) {
                        } else {
                            if (mVideoStatistics.mData == null || context == null) {
                                v0_3 = false;
                            } else if (!mVideoStatistics.mData.has("vt")) {
                                v0_3 = false;
                            } else {
                                String v2 = mVideoStatistics.mData.optString("sv");
                                v4_1 = mVideoStatistics.mData.optLong("pt");
                                UIUtils.a(context, v2
                                        + " api:" + (mVideoStatistics.mData.optLong("at") - v4_1) + " vv:" + (mVideoStatistics.mData.optLong("vt") - v4_1));
                                v0_3 = true;
                            }
                            this.aI = v0_3;
                        }
                    }
                }

                if (mLoadStartRT <= 0) {
                    return;
                }

                if (info != MediaPlayer.MEDIA_INFO_BUFFERING_END && info != MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
                    return;
                }

                JSONObject jo = new JSONObject();
                try {
                    jo.put("load_time", SystemClock.elapsedRealtime() - mLoadStartRT);
                    jo.put("item_id", mArticle != null ? Long.valueOf(mArticle.itemId) : "");
                    jo.put("position", isFromFeed ? "list" : "detail");
                } catch (JSONException jsonException) {
                }
                mLoadStartRT = 0;
                MobClickCombiner.onEvent(BizApplication.getApplication(),
                        "go_start_play",
                        this.getCategoryLabel("click"),
                        this.getGroupId(),
                        0,
                        jo);
                return;
            case CALLBACK_ON_PREPARE:
                this.isPrepared = true;
                if (mWeakHandler != null) {
                    mWeakHandler.removeCallbacks(this.RetryPlayRunnable);
                    mRetryCount = 0;
                    if (this.isJellyBeanMR1) {
                        return;
                    }
                    if (mStartPlayTs <= 0) {
                        if (this.isSplashVideoPlaying) {
                            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "splash_ad", "play", mAdId, 0, mReportJO, 3);
                            AppUtil.a(this.mTrackUrlList, BaseApplication.getApplication());
                        }
                        mStartPlayTs = System.currentTimeMillis();
                    }

                    this.requestPositionDelay();
                    mMediaLayout.sendDismissToolBarMsg();
                    mWeakHandler.postDelayed(new Runnable() {

                        public final void run() {
                            if (mMediaLayout != null) {
                                mMediaLayout.dismissLoadingCover();
                                mMediaLayout.dismissLoading();
                            }
                        }
                    }, 1000L);
                }
                return;
            case CALLBACK_ON_SEEK_COMPLETE:
                if (mMediaLayout == null) {
                    return;
                }
                mMediaLayout.dismissLoading();
                return;
            case CALLBACK_ON_STATE_ERROR:
                if (!(message.obj instanceof Integer)) {
                    return;
                }
                if (mVideoStatistics == null) {
                    return;
                }
                mVideoStatistics.a("video_error_what", "video state error: " + ((Integer) message.obj).intValue());
                return;
            case CALLBACK_ON_RELEASED:
                if (mUsingMediaPlayer != null) {
                    mUsingMediaPlayer.execPendingActions();
                    return;
                } else {
                    return;
                }
            case CALLBACK_ON_MP_EXCEPTION:
                if (!(message.obj instanceof Integer)) {
                    return;
                }
                if (mVideoStatistics == null) {
                    return;
                }
                v1_6 = (Integer) message.obj;
                if (mVideoStatistics.mData != null) {
                    try {
                        int v0_2 = 0;
                        if (mVideoStatistics.hasKey("vt")) {
                            v0_2 = v1_6 + 5000;
                        } else {
                            v0_2 = v1_6;
                        }
                        mVideoStatistics.mData.put("errt", v0_2);
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
                }
                VideoDiagnosis.callbackOnError("exception " + v1_6);
                return;

        }
        return;
    }

    public void handleNoWifiCancelClick() {
        MobClickCombiner.onEvent(BaseApplication.getApplication(),
                "video",
                "net_alert_cancel",
                mArticle != null ? mArticle.groupId : 0L,
                0L);
        this.releaseMedia();
    }

    public void handleNoWifiPositiveClick() {
        this.a(false);
        MobClickCombiner.onEvent(BaseApplication.getApplication(),
                "video",
                "net_alert_confirm",
                mArticle != null ? mArticle.groupId : 0L,
                0L);
    }

    public void handleOrientationChanged(int orientation) {
        if ((this.isVideoVisible()) && !this.Y && mUsingMediaPlayer != null) {
            if (orientation == 0) {
                int currentState = mUsingMediaPlayer.getCurrentState();
                if (currentState == STAT_PAUSED
                        || currentState == STAT_STARTED
                        || currentState == STAT_STOPPED
                        || currentState == STAT_PREPARED
                        || currentState == STAT_INITIALIZED) {
                    if (!this.isFullscreen) {
                        this.handleFullScreenClick(mMediaLayout, null);
                    }
                }
            }
            if (orientation != 1) {
                return;
            }

            if (!this.isFullscreen) {
                return;
            }

            this.handleFullScreenClick(mMediaLayout, null);
        }
    }

    public void handlePatchRootViewClick() {
    }

    public void handlePlayClick(IMediaLayout mediaLayout, View arg14) {
        if (mUsingMediaPlayer != null && this.nonNullContext()) {
            if (mUsingMediaPlayer.isPlaying()) {
                this.pauseVideo();
                mVideoEventReporter.onEvent(isFromFeed ? "feed_pause" : "detail_pause");
                if (mAdId <= 0L) {
                    return;
                }
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(),
                        "embeded_ad",
                        isFromFeed ? "feed_pause" : "detail_pause",
                        mAdId,
                        0L,
                        mReportJO,
                        0);
            } else {
                if (mVideoDataContainer == null || mVideoDataContainer.mVideoInfo == null) {
                    DetailPageListener detailPageListener = mDetailPageListener != null ? mDetailPageListener.get() : null;
                    if (detailPageListener != null) {
                        detailPageListener.onNoData();
                        return;
                    }
                }
                mMediaLayout.sendDismissToolBarMsg();
                this.removeRequestPositionRunnable();
                this.requestPositionDelay();
                if (mUsingMediaPlayer.getCurrentState() != STAT_PAUSED) {
                    mVideoEventReporter.onEvent(isFromFeed ? "feed_play" : "detail_play");
                    this.isPendingPlay = true;
                    mMediaLayout.showMediaPlayer(mVideoContainer);
                    if (mAdId > 0L && (this.j)) {
                        if (this.isFromFeed) {
                            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "click", mAdId, 0L, mReportJO, 2);
                            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "feed_play", mAdId, 0L, mReportJO, 2);
                        } else {
                            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "detail_play", mAdId, 0L, mReportJO, 1);
                            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "detail_show", mAdId, 0L, mReportJO, 1);
                        }
                    }
                    this.f();
                    return;
                }

                if (mAdId > 0L && !this.j) {
                    MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(),
                            "embeded_ad",
                            isFromFeed ? "feed_continue" : "detail_continue",
                            mAdId, 0L, mReportJO, 0);
                }
                mVideoEventReporter.onEvent(isFromFeed ? "feed_continue" : "detail_continue");
                this.a(false);
            }
        }
    }

    public void handleRelatedVideoClick(IMediaLayout mediaLayout, View view) {
        Object tag = view.getTag();
        if (tag instanceof RelatedVideoItem && !android.support.design.a.isTextEmpty(((RelatedVideoItem) tag).mOpenUrl)) {
            MobClickCombiner.onEvent(view.getContext(), "video", "feed_click_related_video", 0L, 0L);
            AdsAppBaseActivity.openUrl(view.getContext(), ((RelatedVideoItem) tag).mOpenUrl, null);
            this.R = true;
            ArticleHelper.c = true;
        }
    }

    public void handleReplayClick() {
        if (mPlayCompleteListenerRef != null) {
            IPlayCompleteListener playCompleteListener = mPlayCompleteListenerRef.get();
            if (playCompleteListener != null) {
                playCompleteListener.onReplay();
            }
        }
        mMediaLayout.sendDismissToolBarMsg();
        this.removeRequestPositionRunnable();
        this.requestPositionDelay();
        if (mUsingMediaPlayer.getCurrentState() == STAT_PLAYBACK_COMPLETE) {
            mVideoEventReporter.onEvent(isFromFeed ? "feed_play" : "detail_play");
        } else {
            mVideoEventReporter.onEvent(isFromFeed ? "feed_continue" : "detail_continue");
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("View", isFromFeed ? "Channel" : "Detail");
                if (this.isFromFeed) {
                    jsonObject.put("View Channel", mCategoryName);
                }
            } catch (Exception exception) {
            }
        }
        this.a(false);
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject();
            if (this.isFromFeed) {
                jsonObject.put("position", "list");
            } else {
                jsonObject.put("position", "detail");
            }
        } catch (JSONException jsonException) {
        }

        this.onEvent("video_play", jsonObject);
        if (mAdId > 0L) {
            if (mUsingMediaPlayer.getCurrentState() == STAT_PLAYBACK_COMPLETE) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(),
                        "embeded_ad",
                        isFromFeed ? "feed_play" : "detail_play",
                        mAdId, 0L, mReportJO, 0);
            } else {
                MobClickCombiner.onEvent(BaseApplication.getApplication(),
                        "embeded_ad",
                        isFromFeed ? "feed_continue" : "detail_continue",
                        mAdId,
                        0L,
                        mReportJO);
            }
        }
    }

    public void handleRetryClick(IMediaLayout mediaLayout, View view) {
        mUsingMediaPlayer.reset();
        mVideoStatistics = new VideoStatistics(BaseApplication.getApplication(), mVideoId);
        mVideoStatistics.setWid(mWid);
        mLoadStartRT = SystemClock.elapsedRealtime();
        if (!this.playAdUrl(true) && mVideoDataContainer != null && mVideoDataContainer.mVideoInfo != null) {
            this.f();
        }
    }

    public void handleRootViewClick(IMediaLayout arg11, View arg12, boolean arg13, boolean arg14) {
        if (mUsingMediaPlayer != null && (!this.isFromFeed || !this.isDirectPlay())) {
            if (this.isSplashVideoPlaying) {
                if (mSplashAdListenerRef == null) {
                    return;
                }
                ISplashAdListener splashAdListener = mSplashAdListenerRef.get();
                if (splashAdListener == null) {
                    return;
                }

                if (mStartPlayTs > 0L) {
                    mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                    mStartPlayTs = 0L;
                }
                splashAdListener.onVideoClick(mTotalPlayTime, MediaHelper.timeToPercent(mCurrentPosition, mDuration));
                return;
            }
            if (this.isPatchVideo()) {
                if (AppData.getInstance().isPosterAdClickEnabled()) {
                    this.handleAdGoLandingClick(false);
                    if (!this.isFullscreen) {
                        return;
                    }
                    if (!this.isFromFeed) {
                        return;
                    }
                    this.releaseMedia();
                    return;
                }

                if (arg13) {
                    mMediaLayout.showPlayBtn(true);
                    mMediaLayout.setPlayIcon(!isVideoPlaying(), false);
                } else {
                    mMediaLayout.showPlayBtn(false);
                }

                mMediaLayout.removeDismissToolBarMsg();
                mMediaLayout.sendDismissToolBarMsg();
                return;
            }

            if (arg13) {
                if ((this.j) && mThirdVideoPartnerData != null
                        && !android.support.design.a.isTextEmpty(mThirdVideoPartnerData.androidOpenUrl)
                        && !android.support.design.a.isTextEmpty(mThirdVideoPartnerData.androidDownloadUrl)
                        && !android.support.design.a.isTextEmpty(mThirdVideoPartnerData.packageName)) {
                    mMediaLayout.showToolBar(arg14, true, false);
                } else if (this.av) {
                    mMediaLayout.showToolBar(arg14, false, !isPatchVideo());
                } else {
                    mMediaLayout.showToolBar(arg14);
                }
            }
            if (mUsingMediaPlayer.isPlaying()) {
                mMediaLayout.removeDismissToolBarMsg();
                mMediaLayout.sendDismissToolBarMsg();
            } else {
                mMediaLayout.removeDismissToolBarMsg();
            }

            if (!arg13) {
                return;
            }
            if (mVideoEventReporter != null) {
                mVideoEventReporter.onEvent(isFromFeed ? "feed_click_screen" : "detail_click_screen");
            }
        }
    }

    public void handleShareClick() {
        if (mPlayCompleteListenerRef != null) {
            IPlayCompleteListener playCompleteListener = mPlayCompleteListenerRef.get();
            if (playCompleteListener != null) {
                playCompleteListener.onShare();
            }
        }
    }

    public void handleSplashSkipClick() {
        if (mSplashAdListenerRef != null) {
            ISplashAdListener splashAdListener = mSplashAdListenerRef.get();
            if (splashAdListener != null) {
                if (mStartPlayTs > 0L) {
                    mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                    mStartPlayTs = 0L;
                }
                splashAdListener.onSkip(mTotalPlayTime, MediaHelper.timeToPercent(mCurrentPosition, mDuration));
            }
        }
    }

    @Override
    public void handleThirdPartnerClick() {
        if (mRefThirdPartnerListner != null) {
            IThirdPartnerListner thirdPartnerListner = mRefThirdPartnerListner.get();
            if (thirdPartnerListner != null) {
                thirdPartnerListner.onClick();
            }
        }
    }

    @Override
    public void handleTopMoreClick(IMediaLayout mediaLayout, View view) {
        if (mShareListenerRef != null) {
            IShareListener shareListener = mShareListenerRef.get();
            if (shareListener != null) {
                shareListener.onTopMoreClick();
            }
        }
    }

    @Override
    public void handleTouchProgress(float scale, boolean right) {
        if (mUsingMediaPlayer != null
                && this.nonNullContext()
                && mCurrentPosition >= 0L
                && mMediaLayout != null) {
            Context context = mRefContext.get();
            int currentState = mUsingMediaPlayer.getCurrentState();
            if (mDuration > 0L) {
                if (currentState != STAT_STARTED && currentState != STAT_PAUSED) {
                    return;
                }
                int step = (int) (scale / (float) mDefaultDragStep * (float) mDragUnit);
                if (right) {
                    mDragPosition = (long) step + mDragPosition;
                } else {
                    mDragPosition -= step;
                }

                if (mDragPosition > mDuration) {
                    mDragPosition = mDuration;
                }

                if (mDragPosition < 0L) {
                    mDragPosition = 0L;
                }
                if (mMediaLayout.showTouchProgress(context, right, mDragPosition, mDuration)) {
                    mDragPosition = mCurrentPosition;
                    mVideoEventReporter.onEvent("fullscreen_drag_process");
                }
            }
        }
    }

    public void handleTouchUp() {
        if (mMediaLayout != null) {
            if (mMediaLayout.dismissTouchProgress()) {
                if (mDragPosition == mCurrentPosition) {
                    return;
                } else if (!this.isFullscreen) {
                    return;
                } else if (mDuration > 0L) {
                    mNewestDragPosition = mDragPosition;
                    this.removeRequestPositionRunnable();
                    this.seekTo(mNewestDragPosition);
                    this.requestPositionDelay();
                    mVideoEventReporter.onEvent(isFromFeed ? "feed_move_bar" : "detail_move_bar");
                    if (!this.b((int) (mCurrentPosition * 100 / mDuration))) {
                        mMediaLayout.sendDismissToolBarMsg();
                        return;
                    }

                    mMediaLayout.showLoading();
                    if (mStartPlayTs > 0L) {
                        mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                        mStartPlayTs = 0L;
                    }

                    this.K = false;
                    if (mVideoStatistics == null) {
                        mMediaLayout.sendDismissToolBarMsg();
                        return;
                    }
                    mVideoStatistics.a(mVideoId, mVideoSource);
                } else {
                    return;
                }
            }
            mMediaLayout.sendDismissToolBarMsg();
        }
    }

    public void handleTrySkipAdClick() {
        AbsApplication application = BaseApplication.getApplication();
        MobClickCombiner.onEvent(application,
                "embeded_ad",
                isFromFeed ? "feed_try_skip" : "detail_try_skip",
                mAdId, 0, mReportJO);
    }

    public void handleVideoCoverGodetail(IMediaLayout mediaLayout, View view) {
        if (this.nonNullContext()) {
            if (mAdId > 0L) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "click", mAdId, 0L, mReportJO, 0);
            }
            if (mArticle == null) {
                return;
            }
            ComponentsManifest.findComponent(DetailIntentCreator.class)
                    .startNewDetailActivity(
                            BaseApplication.getApplication(),
                            mArticle,
                            mAdId,
                            mCategoryName);
        }
    }

    public void handleVideoCoverReplay(IMediaLayout mediaLayout, View view) {
        Context context = view.getContext();
        MobClickCombiner.onEvent(context, "video", isFromFeed ? "feed_replay" : "detail_replay", 0L, 0L);
        try {
            JSONObject jsonObject = new JSONObject();
            if (this.isFromFeed) {
                jsonObject.put("position", "list");
            } else {
                jsonObject.put("position", "detail");
            }
            this.onEvent("video_play", jsonObject);
        } catch (JSONException jsonException) {
        }
        this.handlePlayClick(mediaLayout, view);
    }

    @Override
    public void handleVolume(float arg6, boolean arg7, int volume) {
        if ((this.isFullscreen) && mUsingMediaPlayer != null && mMediaLayout != null) {
            Context context = mRefContext.get();
            int maxVolume = mUsingMediaPlayer.getMaxVolume();
            if (volume <= 0) {
                volume = mUsingMediaPlayer.getCurrentVolume() * 100 / maxVolume;
            }

            float v1 = arg6 / 3f;
            int v1_1 = arg7 ? (int) (v1 + (float) volume) : (int) ((float) volume - v1);
            mUsingMediaPlayer.setVolume(maxVolume * v1_1 / 100, false);
            if (mMediaLayout.showVolume(context, v1_1)) {
                mVideoEventReporter.onEvent("fullscreen_drag_volume");
            }
        }
    }

    private void unregisterConnectivityReceiver() {
        if (this.isReceiverRegistered) {
            AbsApplication application = BaseApplication.getApplication();
            this.isReceiverRegistered = false;
            try {
                application.unregisterReceiver(mBroadcastReceiver);
            } catch (Exception exception) {
            }
        }
    }

    public void reset(Context context, ViewGroup videoContainer, boolean isFromFeed, EnumSet enumSet) {
        this.isFromFeed = isFromFeed;
        if (mRefContext == null || mRefContext.get() != context) {
            mRefContext = new WeakReference(context);
            mVideoContainer = videoContainer;
            if (mMediaLayout != null) {
                mMediaLayout.removeMediaView();
            }
            this.initMediaLayout(context, isFromFeed, enumSet);
            this.isExitintActivity = false;
        }
    }

    public boolean isActivityOnDestroy() {
        return this.isActivityOnDestroy;
    }

    public void setActivityOnDestroy(boolean isActivityOnDestroy) {
        this.isActivityOnDestroy = isActivityOnDestroy;
    }

    public boolean isAd() {
        return mAdId > 0;
    }

    public boolean isCurrentVideoAutoRotatable() {
        return true;
    }

    public boolean isDirectPlay() {
        return this.isDirectPlay;
    }

    public boolean isFullScreen() {
        return this.isFullscreen;
    }

    public boolean isPatchVideo() {
        return mPatchPosition == 1 || mPatchPosition == 2;
    }

    public boolean isPauseFromList() {
        return this.isPauseFromList;
    }

    public boolean isPrepared() {
        return this.isPrepared;
    }

    public boolean isVideoPaused() {
        return mUsingMediaPlayer != null && mUsingMediaPlayer.isPaused();
    }

    public boolean isVideoPlaybackCompleted() {
        return mUsingMediaPlayer != null && mUsingMediaPlayer.getCurrentState() == SSMediaPlayerWrapper.STAT_PLAYBACK_COMPLETE;
    }

    public boolean isVideoPlaying() {
        return mUsingMediaPlayer != null && mUsingMediaPlayer.isPlaying();
    }

    public boolean isVideoVisible() {
        return mMediaLayout != null && mMediaLayout.getVisibility() == View.VISIBLE;
    }

    private boolean j() {
        return !this.isFromFeed
                && mVideoAutoPlayHelperDetail != null
                && mVideoAutoPlayHelperDetail.b;
    }

    private void generateWid() {
        mWid = System.currentTimeMillis() + "_" + AppLog.deviceId();
        this.aI = false;
    }

    private void notifyOnClose() {
        ICloseListener closeListener = mCloseListenerRef != null ? mCloseListenerRef.get() : null;
        if (closeListener != null) {
            closeListener.onClose(false);
        } else {
            Logger.e("VideoController", "close listenerRef is null or empty");
        }
    }

    private boolean hasAdPatch() {
        return mVideoDataContainer != null
                && mVideoDataContainer.mVideoAdInfoList != null
                && mVideoDataContainer.mVideoAdInfoList.size() > 0
                && !this.isPendingPlay
                && NetworkUtils.isWifi(BizApplication.getApplication())
                && !this.isDirectPlay();
    }

    private boolean hasAfterPatchVideo() {
        if (mVideoDataContainer != null
                && mVideoDataContainer.mVideoAdInfoList != null
                && mVideoDataContainer.mVideoAdInfoList.size() > 0) {
            for (int i = 0; i < mVideoDataContainer.mVideoAdInfoList.size(); ++i) {
                VideoAdInfo videoAdInfo = mVideoDataContainer.mVideoAdInfoList.get(i);
                if (videoAdInfo != null
                        && videoAdInfo.patchPosition == PATCH_POSITION_AFTER
                        && videoAdInfo.mVideoItem1 != null) {
                    return true;
                }
            }
        }
        return false;
    }

    private boolean o() {
        return mPatchPosition == PATCH_POSITION_BEFORE
                || mPatchPosition == PATCH_POSITION_MIDDLE && this.hasAfterPatchVideo();
    }

    public void onActivityDestroy() {
        if (mUsingMediaPlayer != null) {
            mUsingMediaPlayer.onDestroy();
        }
    }

    public void onEnterDetailEvent() {
        this.ar = true;
        JSONObject jsonObject = new JSONObject();
        try {
            if (mStartPlayTs > 0L) {
                mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                mStartPlayTs = 0;
            }

            jsonObject.put("duration", mTotalPlayTime);
            jsonObject.put("percent", MediaHelper.timeToPercent(mCurrentPosition, mDuration));
            jsonObject.put("log_extra", mLogExtra);
            jsonObject.put("position", isFromFeed ? "list" : "detail");
            if (mArticle != null) {
                jsonObject.put("item_id", mArticle.itemId);
            }
        } catch (JSONException jsonException) {
        }

        if (mAdId > 0L) {
            MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(),
                    "embeded_ad",
                    "click_feed_auto_play",
                    mAdId, 0L, jsonObject, 0);
        } else {
            AbsApplication application = BaseApplication.getApplication();
            MobClickCombiner.onEvent(application,
                    "enter_detail",
                    "click_feed_auto_play",
                    mArticle != null ? mArticle.groupId : 0L,
                    0L,
                    jsonObject);
        }
    }

    public void onProgressChanged(IMediaLayout mediaLayout, SeekBar seekBar, int arg9, boolean arg10) {
        if (this.nonNullContext()) {
            Context context = mRefContext.get();
            mNewestDragPosition = mDuration > 0L
                    ? (long) (int) ((float) ((long) arg9 * mDuration) / (float) context.getResources().getInteger(com.ss.android.article.browser.R.integer.video_progress_max))
                    : 0L;
        }
    }

    public void onStartTrackingTouch(IMediaLayout mediaLayout, SeekBar seekBar) {
        this.removeRequestPositionRunnable();
        mStartDragPosition = mNewestDragPosition;
        mMediaLayout.removeDismissToolBarMsg();
    }

    public void onStopTrackingTouch(IMediaLayout mediaLayout, SeekBar seekBar) {
        if (mUsingMediaPlayer.getCurrentState() == STAT_PLAYBACK_COMPLETE) {
            mLastVideoPos = mNewestDragPosition;
            if (mMediaLayout != null) {
                mMediaLayout.showMediaPlayer(mVideoContainer);
            }
            this.f();
            return;
        }

        this.removeRequestPositionRunnable();
        this.seekTo(mNewestDragPosition);
        this.requestPositionDelay();
        mMediaLayout.sendDismissToolBarMsg();
        VideoEventReporter v1 = mVideoEventReporter;
        String v0 = this.isFromFeed ? "feed_move_bar" : "detail_move_bar";
        v1.onEvent(v0);
        JSONObject jsonObject = new JSONObject();
        try {
            if (mStartPlayTs > 0L) {
                mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                mStartPlayTs = 0L;
            }

            if (mNewestDragPosition - mStartDragPosition > 0L) {
                jsonObject.put("drag_pct", MediaHelper.timeToPercent(mNewestDragPosition - mStartDragPosition, mDuration));
                jsonObject.put("drag_time", mNewestDragPosition - mStartDragPosition);
            } else {
                jsonObject.put("drag_pct", MediaHelper.timeToPercent(mStartDragPosition - mNewestDragPosition, mDuration) * -1);
                jsonObject.put("drag_time", -1 * mStartDragPosition - mNewestDragPosition);
            }
            jsonObject.put("log_extra", mLogExtra);
            jsonObject.put("position", isFromFeed ? "list" : "detail");
            if (mArticle != null) {
                jsonObject.put("item_id", mArticle.itemId);
            }
        } catch (JSONException jsonException) {
        }
        MobClickCombiner.onEvent(BaseApplication.getApplication(),
                "drag_bar",
                "video_bar",
                mArticle != null ? mArticle.groupId : 0L,
                mAdId,
                jsonObject);
        if (this.b(seekBar.getProgress())) {
            mMediaLayout.showLoading();
            if (this.isLiveVideo) {
                MobClickCombiner.onEvent(BaseApplication.getApplication(),
                        "live",
                        "loading",
                        mArticle != null ? mArticle.groupId : 0L,
                        0L);
            }
            if (mStartPlayTs > 0L) {
                mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                mStartPlayTs = 0L;
            }

            this.K = false;
            if (mVideoStatistics != null) {
                mVideoStatistics.a(mVideoId, mVideoSource);
            }
        }
    }

    private void executePendingAction() {
        if (!this.ab && mPendingActionList != null && !mPendingActionList.isEmpty()) {
            this.ab = true;
            Iterator<Runnable> iterator = new ArrayList(mPendingActionList).iterator();
            while (iterator.hasNext()) {
                iterator.next().run();
            }
            mPendingActionList.clear();
            this.ab = false;
        }
    }

    public void pauseAtList() {
        Logger.d("VideoController", "pauseAtList");
        if (mMediaLayout != null) {
            this.isPauseFromList = true;
            if (mGetPlayUrlThread != null) {
                mGetPlayUrlThread.cancelRequest();
            }

            if (mUsingMediaPlayer != null) {
                mUsingMediaPlayer.pause();
            }

            mMediaLayout.dismissNoWifiNoticeDialog();
            mMediaLayout.releaseMediaPlayer();
            mMediaLayout.setKeepScreenOn(false);
            this.removeRequestPositionRunnable();
            mWeakHandler.removeCallbacks(this.RetryPlayRunnable);
            if (mCoverImageIvRef != null) {
                mCoverImageIvRef.clear();
            }

            if (mVideoContainerRef != null) {
                Object v0 = mVideoContainerRef.get();
                if (v0 != null && ((v0 instanceof RelativeLayout))) {
                    ((RelativeLayout) v0).removeAllViews();
                    ((View) v0).setVisibility(View.GONE);
                }

                mVideoContainerRef.clear();
            }

            this.unregisterConnectivityReceiver();
            this.clearPendingActions();
        }
    }

    public void pauseVideo() {
        Logger.d("VideoController", "pauseVideo");
        if (mStartPlayTs > 0L) {
            mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
            mStartPlayTs = 0L;
        }

        if (mUsingMediaPlayer != null) {
            mUsingMediaPlayer.pause();
        }

        this.abandonAudioFocus();
        mMediaLayout.removeDismissToolBarMsg();
        mMediaLayout.setKeepScreenOn(false);
        if (!this.av) {
            mMediaLayout.showToolBar(true, false, !this.isPatchVideo() && this.av);
            mMediaLayout.setPlayIcon(true, this.isLiveVideo);
        } else {
            if (!this.isPatchVideo()) {
                return;
            }

            if (AppData.getInstance().isPosterAdClickEnabled()) {
                return;
            }

            mMediaLayout.setPlayIcon(true, this.isLiveVideo);
        }
    }

    public boolean play(CellRef cellRef, int arg15, int arg16, View view, View arg18, boolean idDirectPlay) {
        if (this.getContext() != null && (android.support.design.a.isTest(this.getContext()))) {
            Toast.makeText(this.getContext(), "old videoplayer", Toast.LENGTH_SHORT).show();
        }
        VideoCacheManager.getInstance().cancelPreDownload();
        if (!this.nonNullContext() || mMediaLayout == null) {
            return false;
        } else if (cellRef == null) {
            this.releaseMedia(false);
            return false;
        } else {
            Article article = cellRef.article;
            if (article != null && !android.support.design.a.isTextEmpty(article.videoId)) {
                if (!android.support.design.a.isTextEmpty(mVideoId) && !mVideoId.equals(article.videoId)) {
                    this.releaseMedia(true);
                }
                if (!AppData.getInstance().hasVideoKeepPos() || !TextUtils.equals(article.videoId, VideoPref.getLastVideoId())) {
                    mLastVideoPos = -1;
                } else {
                    mLastVideoPos = VideoPref.getLastVideoPos();
                    MobClickCombiner.onEvent(BaseApplication.getApplication(), "list_over", "list_continue");
                }

                mMediaLayout.resetClaritySelectors();
                this.generateWid();
                this.isPauseFromList = false;
                this.pendingPausedVideo = false;
                this.ag = null;
                this.isActivityOnDestroy = false;
                mAdId = cellRef.getAdId();
                this.isDirectPlay = idDirectPlay;
                mLogExtra = cellRef.logExtra;
                mLogPb = cellRef.logPb;
                mReportJO = new JSONObject();
                try {
                    if (!android.support.design.a.isTextEmpty(mLogExtra)) {
                        mReportJO.put("log_extra", mLogExtra);
                    }
                } catch (JSONException jsonException) {
                }
                if (mUsingMediaPlayer != null) {
                    if (mAbandonMediaPalyer != null) {
                        mAbandonMediaPalyer.onDestroy();
                    }
                    mAbandonMediaPalyer = mUsingMediaPlayer;
                    mUsingMediaPlayer.onRelease();
                }

                mWeakHandler = new WeakHandler(this);
                mUsingMediaPlayer = new SSMediaPlayerWrapper(mWeakHandler, false);
                mTotalPlayTime = 0;
                this.isPlayError = false;
                this.setBindedTag(article);
                mCoverImageIvRef = new WeakReference(view);
                mVideoContainerRef = new WeakReference(arg18);
                mCategoryName = cellRef.category;
                mArticle = article;
                this.isLiveVideo = article.videoType == 1;
                this.isFromFeed = true;
                mLoop = 0;
                mMediaLayout.setOuterVideoCellType(cellRef.videoStyle);
                if (cellRef.videoStyle == 7
                        || cellRef.videoStyle == 8
                        || cellRef.videoStyle == 12) {
                    mMediaLayout.setTitleTextSize(16);
                } else if (cellRef.videoStyle == 9) {
                    mMediaLayout.setTitleTextSize(15);
                }

                if (this.isAd()) {
                    mMediaLayout.showOrHideWatermark(false);
                } else {
                    mMediaLayout.showOrHideWatermark(true);
                }
                mMediaLayout.showMediaPlayer(mVideoContainer);
                mMediaLayout.setTitle(article.title);
                mMediaLayout.setBtnAdInfo(article.aF, mRefContext);
                AppData.getInstance();
                mMediaLayout.setTheme(AppData.isNightMode());
                long lastVideoPos = mLastVideoPos > 0 ? mLastVideoPos : 0;
                this.refreshTimeUI(lastVideoPos, article.videoDuration * 1000);
                mDuration = -1;
                this.shouldPreloadVideo = shouldPreloadVideo(article);
                if (this.isLiveVideo) {
                    mVideoWidth = view.getWidth();
                    mVideoHeight = view.getHeight();
                }
                if (mArticle != null) {
                    mVideoEventReporter.setData("video", mArticle, mAdId, mArticle.videoSubjectId);
                }
                if (!this.isFromFeed || !idDirectPlay) {
                    mVideoEventReporter.onEvent(this.isFromFeed ? "feed_play" : "detail_play");
                }
                if (mAdId > 0) {
                    if ((this.isFromFeed) && !idDirectPlay) {
                        MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(),
                                "embeded_ad",
                                "feed_play",
                                mAdId,
                                0,
                                mReportJO,
                                2);
                    }
                    AppUtil.a(article.adVideoClickTrackUrls, BaseApplication.getApplication());
                }

                this.setContainerSize(view.getWidth(), view.getHeight());
                this.syncPosition(false);
                mVideoStatistics = new VideoStatistics(BaseApplication.getApplication(), article.videoId);
                mVideoStatistics.setWid(mWid);
                mLoadStartRT = SystemClock.elapsedRealtime();
                this.playVideo("", article.videoId, article.sp());
                if (mArticle != null) {
                    JSONObject jsonObject = new JSONObject();
                    try {
                        jsonObject.put("position", this.isFromFeed ? "list" : "detail");
                        jsonObject.put("item_id", mArticle.itemId);
                        jsonObject.put("aggr_type", mArticle.aggrType);
                        jsonObject.put("log_extra", mLogExtra);
                    } catch (JSONException jsonException) {
                    }

                    if (!idDirectPlay) {
                        this.onEvent("video_play", jsonObject);
                    } else if (mAdId > 0) {
                        MobAdClickCombiner.onAdEvent(
                                BaseApplication.getApplication(),
                                "embeded_ad",
                                "feed_auto_play",
                                mAdId,
                                0, jsonObject,
                                2);
                    } else {
                        MobClickCombiner.onEvent(
                                BaseApplication.getApplication(),
                                "video_play",
                                "feed_auto_play",
                                mArticle.groupId,
                                0,
                                jsonObject);
                    }
                }
                this.registerConnectivityReceiver();
                this.isExitintActivity = false;
                return true;
            }

            this.releaseMedia(false);
            return false;
        }
    }

    public boolean play(String url, String categoryName, String title, long adId, Article article,
                        String videoId, int sp, int videoWidth, int videoHeight, List<String> trackUrlList,
                        long lastPos, String arg34, boolean isDirectPlay, String externalUrl,
                        String logextra, JSONObject jsonObject) {
        return this.play(url, categoryName, title, adId, article, videoId, sp,
                videoWidth, videoHeight, trackUrlList, lastPos, arg34, isDirectPlay,
                externalUrl, false, logextra, jsonObject);
    }

    public boolean play(String url, String categoryName, String title,
                        long adId, Article article,
                        String videoId, int sp,
                        int videoWidth,
                        int videoHeight,
                        List<String> trackUrlList, long lastPos,
                        String arg26, boolean isDirectPlay,
                        String externalUrl, boolean arg29,
                        String logExtra, JSONObject arg31) {
        if (this.getContext() != null && (android.support.design.a.isTest(this.getContext()))) {
            Toast.makeText(this.getContext(), "old videoplayer", Toast.LENGTH_SHORT).show();
        }
        VideoCacheManager.getInstance().cancelPreDownload();
        if (!this.nonNullContext()) {
            return false;
        }

        if (android.support.design.a.isTextEmpty(videoId) && android.support.design.a.isTextEmpty(url)) {
            Logger.e("VideoController", "No video info");
            return false;
        }

        if (!android.support.design.a.isTextEmpty(mVideoId) && !mVideoId.equals(videoId) && this.isVideoVisible()) {
            this.releaseMedia(true);
        }

        mMediaLayout.resetClaritySelectors();
        int v2_1 = 0;
        if (!AppData.getInstance().hasVideoKeepPos()
                || !TextUtils.equals(videoId, VideoPref.getLastVideoId())) {
            mLastVideoPos = lastPos;
        } else {
            long lastVideoPos = VideoPref.getLastVideoPos();
            if (lastVideoPos > 0 && lastPos <= 0) {
                mLastVideoPos = lastVideoPos;
                v2_1 = 1;
                MobClickCombiner.onEvent(BaseApplication.getApplication(), "list_over", "detail_continue");
            } else {
                mLastVideoPos = lastPos;
            }
        }
        int v3 = v2_1 != 0 || lastPos > 0 ? v2_1 : 1;
        this.generateWid();
        this.isPauseFromList = false;
        this.pendingPausedVideo = false;
        this.isActivityOnDestroy = false;
        this.isDirectPlay = isDirectPlay;
        if (arg31 != null) {
            mLogPb = arg31.optJSONObject("log_pb");
            this.mSearchResultId = arg31.optLong("search_result_id");
            this.mSource = arg31.optString("source");
            this.mQuery = arg31.optString("query");
        }

        mArticle = article;
        this.isLiveVideo = article.isLiveVideo();
        this.isPlayError = false;
        mCategoryName = categoryName;
        mMediaLayout.setVideoSize(videoWidth, videoHeight);
        mMediaLayout.showMediaPlayer(mVideoContainer);
        mMediaLayout.dismissNewCover();
        mMediaLayout.dismissAllEndCover();
        this.isFromFeed = false;
        mDuration = -1;
        this.shouldPreloadVideo = shouldPreloadVideo(article);
        mMediaLayout.setTitle(title);
        this.ag = arg26;
        mLoop = 0;
        if (arg29) {
            this.setContainerSize(videoWidth, videoHeight);
        } else {
            this.setContainerSize(-1, videoHeight);
        }

        if (mVideoAutoPlayHelperDetail != null) {
            mVideoAutoPlayHelperDetail.a(mMediaLayout, this.isFromFeed, mVideoContainer);
            if (!mVideoAutoPlayHelperDetail.a) {
                Context context = this.nonNullContext() ? mRefContext.get() : null;
                int orientation = (context instanceof Activity) ? ((Activity) context).getRequestedOrientation() : 1;
                if (orientation == 1) {
                    this.requestOrienation(0);
                }
            }
        }
        if (v3 != 0 && !this.j) {
            mExternalUrl = externalUrl;
            mLogExtra = logExtra;
            mAdId = adId;
            this.av = arg29;
            mReportJO = new JSONObject();
            try {
                if (!android.support.design.a.isTextEmpty(mLogExtra)) {
                    mReportJO.put("log_extra", mLogExtra);
                }
            } catch (JSONException jsonException) {
            }

            if (mArticle != null) {
                mVideoEventReporter.setData("video", mArticle, mAdId, mArticle.videoSubjectId);
            }
            mVideoEventReporter.onEvent(this.isFromFeed ? "feed_play" : "detail_play");
            if (mAdId > 0) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(), "embeded_ad", "detail_play", mAdId, 0, mReportJO, 0);
                AppUtil.a(trackUrlList, BaseApplication.getApplication());
            }
            mVideoStatistics = new VideoStatistics(BaseApplication.getApplication(), videoId);
            mVideoStatistics.setWid(mWid);
            mLoadStartRT = SystemClock.elapsedRealtime();
            JSONObject jsonObject = new JSONObject();
            if (mArticle != null) {
                try {
                    jsonObject.put("position", this.isFromFeed ? "list" : "detail");
                    jsonObject.put("item_id", mArticle.itemId);
                    jsonObject.put("aggr_type", mArticle.aggrType);
                } catch (JSONException jsonException) {
                }
            }

            if (this.j()) {
                if (!this.isFromFeed) {
                    try {
                        jsonObject.put("version_type", "high");
                    } catch (JSONException jsonException) {
                    }
                    Context context;
                    if (mRefContext == null) {
                        context = null;
                    } else {
                        context = mRefContext.get();
                    }
                    VideoAutoPlayHelperDetail.onEvent(context,
                            "video_play_auto",
                            this.getCategoryLabel("click"),
                            mArticle.groupId,
                            mAdId,
                            jsonObject);
                }
            } else {
                this.onEvent("video_play", jsonObject);
            }
            mTotalPlayTime = 0;
            this.playVideo(url, videoId, sp);
            if (this.isAd()) {
                mMediaLayout.showOrHideWatermark(false);
            } else {
                mMediaLayout.showOrHideWatermark(true);
            }
            this.registerConnectivityReceiver();
            this.isExitintActivity = false;
            return true;
        }
        mMediaLayout.setVideoSize(mVideoWidth, mVideoHeight);
        this.pendingPausedVideo = this.j && !this.isDirectPlay;
        if (this.isDirectPlay && mArticle != null) {
            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject.put("position", "detail");
                jsonObject.put("item_id", mArticle.itemId);
                jsonObject.put("aggr_type", mArticle.aggrType);
            } catch (JSONException jsonException) {
            }

            this.onEvent("video_play", jsonObject);
            if (mAdId > 0) {
                MobAdClickCombiner.onAdEvent(BaseApplication.getApplication(),
                        "embeded_ad",
                        "detail_play",
                        mAdId,
                        0,
                        mReportJO,
                        0);
            }
        }
        this.continuePlay(this.isDirectPlay);
        this.registerConnectivityReceiver();
        if (this.isAd()) {
            mMediaLayout.showOrHideWatermark(false);
        } else {
            mMediaLayout.showOrHideWatermark(true);
        }
        return true;
    }

    public boolean playSplashUrl(String localUrl,
                                 String videoId,
                                 String categoryName,
                                 String title,
                                 long adId,
                                 int videoWidth,
                                 int videoHeight,
                                 List<String> trackUrlList,
                                 String externalUrl,
                                 String logExtra,
                                 int topMargin,
                                 boolean showSplashLogo,
                                 boolean showJunpBtn) {
        Logger.d("VideoController", "video local url " + localUrl);
        Logger.d("VideoController", "video mVideoId " + videoId);
        if (!this.nonNullContext()) {
            return false;
        }

        if (!android.support.design.a.isTextEmpty(videoId)
                && !android.support.design.a.isTextEmpty(localUrl)) {
            if (!android.support.design.a.isTextEmpty(mVideoId)
                    && !mVideoId.equals(videoId)
                    && this.isVideoVisible()) {
                this.releaseMedia(true);
            }

            this.generateWid();
            this.isPauseFromList = false;
            this.pendingPausedVideo = false;
            this.isActivityOnDestroy = false;
            mExternalUrl = externalUrl;
            mAdId = adId;
            this.isPlayError = false;
            mCategoryName = categoryName;
            mMediaLayout.setIsSplashAdVideo(true, showSplashLogo, showJunpBtn);
            mMediaLayout.setVideoSize(videoWidth, videoHeight);
            mMediaLayout.showMediaPlayer(mVideoContainer);
            if (mMediaLayout.getLayoutParams() instanceof FrameLayout.LayoutParams) {
                mVideoContainer.getLocationInWindow(mVideoContainerLocationInWindow);
                FrameLayout.LayoutParams mediaLayoutLp = mMediaLayout.getLayoutParams();
                if (mediaLayoutLp != null) {
                    mediaLayoutLp.topMargin = topMargin;
                    mediaLayoutLp.leftMargin = 0;
                    mediaLayoutLp.gravity = 51;
                    mMediaLayout.setLayoutParams(mediaLayoutLp);
                }
            } else {
                Logger.d("VideoController", "syncPositionForSplash layout params!");
            }

            this.isFromFeed = false;
            mDuration = -1;
            mMediaLayout.setTitle(title);
            if (mUsingMediaPlayer != null) {
                if (mAbandonMediaPalyer != null) {
                    mAbandonMediaPalyer.onDestroy();
                }
                mAbandonMediaPalyer = mUsingMediaPlayer;
                mUsingMediaPlayer.onRelease();
            }
            mWeakHandler = new WeakHandler(this);
            mUsingMediaPlayer = new SSMediaPlayerWrapper(mWeakHandler, true);
            this.av = true;
            this.setContainerSize(videoWidth, videoHeight);
            this.isSplashVideoPlaying = true;
            mTotalPlayTime = 0;
            mMediaLayout.dismissToolBar(false, true);
            mMediaLayout.trySetTitleVisiable(false);
            mMediaLayout.showLoading();
            try {
                this.shouldPreloadVideo = false;
                this.startPlayVideo(localUrl);
            } catch (Exception exception) {
            }

            mLogExtra = logExtra;
            mReportJO = new JSONObject();
            try {
                if (!android.support.design.a.isTextEmpty(mLogExtra)) {
                    mReportJO.put("log_extra", mLogExtra);
                }
            } catch (JSONException jsonException) {
            }
            if (mArticle != null) {
                mVideoEventReporter.setData("video", mArticle, mAdId, mArticle.videoSubjectId);
            }
            this.mTrackUrlList = trackUrlList;
            this.isExitintActivity = false;
            return true;
        } else {
            Logger.e("VideoController", "No video info");
            return false;
        }
    }

    private void clearPendingActions() {
        if (mPendingActionList != null && !mPendingActionList.isEmpty()) {
            mPendingActionList.clear();
        }
    }

    private void abandonAudioFocus() {
        try {
            if (mMyOnAudioFocusChangeListener == null) {
                return;
            }
            ((AudioManager) AbsApplication.getApplication().getSystemService(Context.AUDIO_SERVICE)).abandonAudioFocus(mMyOnAudioFocusChangeListener);
            mMyOnAudioFocusChangeListener = null;
        } catch (Throwable v0) {
        }
    }

    public void registerReshowEndCoverCallback() {
        this.aV = new ReshowEndCoverCallback(this);
        if (this.aV != null) {
            CallbackCenter.addCallback(IVideoController.RESHOW_END_COVER, this.aV);
        }
    }

    public void registerStopEndCoverCallback() {
        this.aW = new StopAutoPlayAnimationCallback(this);
        if (this.aW != null) {
            CallbackCenter.addCallback(IVideoController.STOP_END_COVER, this.aW);
        }
    }

    public void releaseMedia() {
        this.isPauseFromList = false;
        this.pendingPausedVideo = false;
        this.releaseMedia(false);
    }

    public void releaseMediaFromSplash(boolean arg11, int break_reason) {
        JSONObject v8;
        long v6 = 0;
        if (arg11) {
            JSONObject v1 = null;
            try {
                v8 = new JSONObject();

                if (mStartPlayTs > v6) {
                    mTotalPlayTime += System.currentTimeMillis() - mStartPlayTs;
                    mStartPlayTs = 0;
                }

                v8.put("break_reason", break_reason);
                v8.put("duration", mTotalPlayTime);
                v8.put("percent", MediaHelper.timeToPercent(mTotalPlayTime, mDuration));
                v8.put("log_extra", mLogExtra);
                MobAdClickCombiner.onAdEvent(BizApplication.getApplication(), "splash_ad", "play_break", mAdId, v6, v8, 0);
            } catch (JSONException v0) {
                v0.printStackTrace();
            }
        }

        Logger.d("VideoController", "mDuration :" + mDuration);
        Logger.d("VideoController", "mCurrent :" + mCurrentPosition);
        Logger.d("VideoController", "mTotalPlayTime :" + mTotalPlayTime);
        this.releaseMedia();
    }

    public void releaseWhenOnPause() {
        if (AppData.getInstance().getAbSettings().isEnableFeedBackWithVideoLog()) {
            SSMediaPlayerWrapper.onIjkLog("releaseWhenOnPause");
        }

        if (!this.isPauseFromList) {
            if (this.aB) {
                this.aB = false;
                this.pauseAtList();
            } else {
                this.releaseMedia();
            }
        }
    }

    public void releaseWithMiniVideo(boolean arg2) {
        if (arg2) {
            this.releaseMedia(true);
        }
    }

    public void requestOrienation(int arg6) {
        int v4 = 1024;
        if (this.nonNullContext()) {
            int v1 = arg6 == 0 || arg6 == 8 ? 1 : 0;
            if (v1 == 0) {
                this.Y = false;
            }

            Object v0 = mRefContext.get();
            if (!(v0 instanceof Activity)) {
                return;
            }

            try {
                ((Activity) v0).setRequestedOrientation(arg6);
            } catch (Throwable v2) {
            }

            if (mMediaLayout != null) {
                mMediaLayout.dismissVolume();
                mMediaLayout.dismissTouchProgress();
            }

            if (v1 != 0) {
                ((Activity) v0).getWindow().setFlags(v4, v4);
            } else {
                this.S = System.currentTimeMillis();
                ((Activity) v0).getWindow().clearFlags(v4);
            }
        }
    }

    @Override
    public void resumeMedia(View coverImageIv, View videoContainer) {
        Logger.d("VideoController", "resumeMedia");
        if (mCoverImageIvRef == null || mCoverImageIvRef.get() == null) {
            mCoverImageIvRef = new WeakReference(coverImageIv);
            mVideoContainerRef = new WeakReference(videoContainer);
        }

        if (!this.R) {
            mCoverImageIvRef = new WeakReference(coverImageIv);
            mVideoContainerRef = new WeakReference(videoContainer);
            mMediaLayout.setVisibility(View.VISIBLE);
        }
        this.R = false;
    }

    public void resumeVideo() {
        this.executeOrPendingAction(new Runnable() {

            public final void run() {
                if (mUsingMediaPlayer != null
                        && !mUsingMediaPlayer.isPlaying()
                        && mMediaLayout != null) {
                    NetworkType networkType = null;
                    if (VideoController.this.nonNullContext()) {
                        networkType = NetworkUtils.getNetworkType(mRefContext.get());
                    }

                    if (mMediaLayout != null
                            && mMediaLayout.isNoWifiDialogShowing()
                            && networkType != null
                            && !AppData.getInstance().userAllowUseMobileNet
                            && networkType != NetworkType.WIFI
                            && networkType != NetworkType.NONE) {
                        return;
                    }

                    Logger.d("VideoController", "resumeVideo");
                    mMediaLayout.setVisibility(View.VISIBLE);
                    mMediaLayout.sendDismissToolBarMsg();
                    VideoController.this.removeRequestPositionRunnable();
                    VideoController.this.requestPositionDelay();
                    if (mUsingMediaPlayer.getCurrentState() == STAT_PLAYBACK_COMPLETE) {
                        mVideoEventReporter.onEvent(isFromFeed ? "feed_play" : "detail_play");
                    } else {
                        mVideoEventReporter.onEvent(isFromFeed ? "feed_continue" : "detail_continue");
                    }

                    VideoController.this.a(false);
                    if (mAdId <= 0L) {
                        return;
                    }

                    if (!VideoController.this.nonNullContext()) {
                        return;
                    }

                    if (mUsingMediaPlayer.getCurrentState() == STAT_PLAYBACK_COMPLETE) {
                        Application application = BaseApplication.getApplication();
                        MobAdClickCombiner.onAdEvent(application,
                                "embeded_ad",
                                isFromFeed ? "feed_play" : "detail_play",
                                mAdId,
                                0L,
                                mReportJO,
                                0);
                    } else {
                        Application application = BaseApplication.getApplication();
                        MobAdClickCombiner.onAdEvent(application,
                                "embeded_ad",
                                isFromFeed ? "feed_continue" : "detail_continue",
                                mAdId,
                                0L,
                                mReportJO,
                                0);
                    }
                }
            }
        });
    }

    public void setFullScreenListener(IVideoFullscreen videoFullscreen) {
        mVideoFullscreenRef = new WeakReference(videoFullscreen);
    }

    public void setOnCloseListener(ICloseListener closeListener) {
        mCloseListenerRef = new WeakReference(closeListener);
    }

    public void setPlayCompleteListener(IPlayCompleteListener playCompleteListener) {
        mPlayCompleteListenerRef = new WeakReference(playCompleteListener);
    }

    public void setShareListener(IShareListener shareListener) {
        mShareListenerRef = new WeakReference(shareListener);
    }

    public void setSplashAdListener(ISplashAdListener splashAdListener) {
        mSplashAdListenerRef = new WeakReference(splashAdListener);
    }

    public void showAdGoLanding(String externalUrl) {
        mExternalUrl = externalUrl;
        if (mAdId > 0
                && !this.isFromFeed
                && !android.support.design.a.isTextEmpty(mExternalUrl)
                && !this.isPatchVideo()) {
            mMediaLayout.setAdGoLanding(true);
        }
    }

    public boolean showBackwardVideo(Article article, long arg10, String arg12, int arg13, int arg14, String arg15, String arg16, long arg17, String arg19) {
        if (!this.nonNullContext()) {
            return false;
        } else {
            String v3 = article.videoId;
            if (android.support.design.a.isTextEmpty(v3)) {
                Logger.e("VideoController", "No video info");
                return false;
            } else {
                if (!android.support.design.a.isTextEmpty(mVideoId) && !mVideoId.equals(v3) && (this.isVideoVisible())) {
                    this.releaseMedia(true);
                }

                if (mMediaLayout != null && mVideoDataContainer != null && mVideoDataContainer.mVideoInfo != null) {
                    mMediaLayout.restoreClaritySelectByCache(
                            VideoClarityHelper.getDefinitionStr(getVideoItemByClarity(mVideoDataContainer.mVideoInfo).definition), VideoClarityHelper.getSupportVideoInfos(mVideoDataContainer.mVideoInfo));
                }

                int v2_1 = 0;
                if (!AppData.getInstance().hasVideoKeepPos() || !TextUtils.equals(v3, VideoPref.getLastVideoId())) {
                    mLastVideoPos = arg10;
                } else {
                    long v4 = VideoPref.getLastVideoPos();
                    if (v4 > 0 && arg10 <= 0) {
                        mLastVideoPos = v4;
                        v2_1 = 1;
                    } else {
                        mLastVideoPos = arg10;
                    }
                }

                if (v2_1 == 0 && arg10 <= 0) {
                    v2_1 = 1;
                }

                this.generateWid();
                mVideoId = v3;
                this.isPauseFromList = false;
                this.pendingPausedVideo = false;
                this.isActivityOnDestroy = false;
                this.isDirectPlay = false;
                mArticle = article;
                this.isLiveVideo = article.isLiveVideo();
                this.isPlayError = false;
                mCategoryName = arg12;
                mMediaLayout.setVideoSize(arg13, arg14);
                mMediaLayout.showMediaPlayer(mVideoContainer);
                this.isFromFeed = false;
                mDuration = -1;
                this.shouldPreloadVideo = shouldPreloadVideo(article);
                mMediaLayout.setTitle(article.title);
                this.ag = arg15;
                mLoop = 0;
                this.setContainerSize(-1, arg14);
                if (v2_1 == 0 || this.j) {
                    mMediaLayout.setVideoSize(mVideoWidth, mVideoHeight);
                    this.pendingPausedVideo = this.j && !this.isDirectPlay;
                } else {
                    mExternalUrl = arg16;
                    mLogExtra = arg19;
                    mAdId = arg17;
                    this.av = false;
                    mTotalPlayTime = 0;
                    this.isExitintActivity = false;
                }

                if (mArticle != null) {
                    if (mArticle.largeImageList != null) {
                        mMediaLayout.showCover(mArticle.largeImageList, this.isFromFeed);
                    } else if (mArticle.mLoadingCoverImageInfo != null) {
                        mMediaLayout.showCover(mArticle.mLoadingCoverImageInfo, this.isFromFeed);
                    } else if (mArticle.middleImage != null) {
                        mMediaLayout.showCover(mArticle.middleImage, this.isFromFeed);
                    }
                }
                return true;
            }
        }
    }

    public void showNewCover(Article article) {
        if (mMediaLayout != null) {
            mMediaLayout.showNewCover(article);
        }
    }

    public void showThirdPartnerGuide(ThirdVideoPartnerData thirdVideoPartnerData, IThirdPartnerListner thirdPartnerListner) {
        mThirdVideoPartnerData = thirdVideoPartnerData;
        mRefThirdPartnerListner = new WeakReference(thirdPartnerListner);
    }

    public void stopAutoPlayAnimation() {
        if (mMediaLayout != null) {
            mMediaLayout.stopAutoPlayEndCover();
        }
    }

    public void surfaceChanged(IMediaLayout mediaLayout, SurfaceHolder surfaceHolder, int format, int width, int height) {
        Logger.d("VideoController", "surfaceChanged, format = " + format + ", width = " + width + ", height = " + height);
    }

    public void surfaceCreated(IMediaLayout mediaLayout, SurfaceHolder surfaceHolder) {
        Logger.d("VideoController", "surfaceCreated");
        if (!this.isSurfaceCreated) {
            this.ai = true;
            if (mUsingMediaPlayer != null && (this.nonNullContext())) {
                mUsingMediaPlayer.setDisplay(surfaceHolder);
                this.isSurfaceCreated = true;
                mRefContext.get();
                if (this.pendingPausedVideo) {
                    this.pauseVideo();
                } else {
                    this.executePendingAction();
                }
            }
        }
    }

    public void surfaceDestroyed(IMediaLayout arg3, SurfaceHolder arg4) {
        this.ai = false;
        this.isSurfaceCreated = false;
        Logger.d("VideoController", "surfaceDestroyed");
    }

    public void syncPosition(boolean postSync) {
        if (!this.isFullscreen) {
            View coverImageIv = mCoverImageIvRef != null ? mCoverImageIvRef.get() : null;
            if (coverImageIv == null) {
                return;
            }

            if (!this.isFromFeed) {
                return;
            }

            coverImageIv.getLocationInWindow(mCoverImageIvLocationInWindow);
            if (mMediaLayout.getLayoutParams() instanceof FrameLayout.LayoutParams) {
                mVideoContainer.getLocationInWindow(mVideoContainerLocationInWindow);
                if (Build.VERSION.SDK_INT > 19
                        && mCoverImageIvLocationInWindow[1] - mVideoContainerLocationInWindow[1] <= -mVideoContainer.getTop()) {
                    this.dismiss(true);
                    return;
                }

                if (postSync) {
                    mWeakHandler.post(mSyncPositionRunnable);
                    return;
                }

                FrameLayout.LayoutParams lp = mMediaLayout.getLayoutParams();
                if (lp == null) {
                    return;
                }
                lp.topMargin = mCoverImageIvLocationInWindow[1] - mVideoContainerLocationInWindow[1];
                lp.leftMargin = mCoverImageIvLocationInWindow[0];
                lp.gravity = 51;
                mMediaLayout.setLayoutParams(lp);
            }
        }
    }

    public void textureViewCreated(IMediaLayout mediaLayout, Surface surface) {
        Logger.d("VideoController", "textureViewCreated");
        mUsingMediaPlayer.setSurface(surface);
        this.isSurfaceCreated = true;
        if (this.pendingPausedVideo) {
            this.pauseVideo();
        } else {
            this.executePendingAction();
        }
    }

    public void unRegisterReceiver() {
        this.unregisterConnectivityReceiver();
    }

    public void unregisterReshowEndCoverCallback() {
        if (this.aV != null) {
            CallbackCenter.removeCallback(IVideoController.RESHOW_END_COVER, this.aV);
        }
    }

    public void unregisterStopEndCoverCallback() {
        if (this.aW != null) {
            CallbackCenter.removeCallback(IVideoController.STOP_END_COVER, this.aW);
        }
    }

    final static class MyOnAudioFocusChangeListener implements AudioManager.OnAudioFocusChangeListener {

        public final void onAudioFocusChange(int focusChange) {
        }
    }

    final class SetAutoRotateCallback implements SSCallback {
        private WeakReference<VideoController> mVideoControllerRef;

        SetAutoRotateCallback(VideoController videoController) {
            mVideoControllerRef = new WeakReference(videoController);
        }

        public final Object onCallback(Object[] objects) {
            if (objects != null && objects.length > 0 && ((objects[0] instanceof Boolean))) {
                boolean disableAutoRotate = ((Boolean) objects[0]).booleanValue();
                VideoController videoController = mVideoControllerRef.get();
                if (videoController != null && videoController.mMediaLayout != null && videoController.isVideoVisible()) {
                    if (disableAutoRotate) {
                        videoController.mMediaLayout.disableAutoRotate();
                    } else if (!videoController.j && a(videoController)) {
                        videoController.mMediaLayout.enableAutoRotate();
                    }
                }
            }
            return null;
        }
    }

    final class ReshowEndCoverCallback implements SSCallback {
        private WeakReference<VideoController> mVideoControllerRef;

        ReshowEndCoverCallback(VideoController videoController) {
            mVideoControllerRef = new WeakReference(videoController);
        }

        public final Object onCallback(Object[] args) {
            VideoController videoController = mVideoControllerRef != null ? mVideoControllerRef.get() : null;
            if (videoController != null && videoController.getMediaViewLayout() != null) {
                videoController.getMediaViewLayout().reshowEndCover();
            }
            return null;
        }
    }

    final class StopAutoPlayAnimationCallback implements SSCallback {
        private WeakReference<VideoController> mVideoControllerRef;

        StopAutoPlayAnimationCallback(VideoController videoController) {
            mVideoControllerRef = new WeakReference(videoController);
        }

        @Override
        public final Object onCallback(Object[] args) {
            VideoController videoController = mVideoControllerRef != null ? mVideoControllerRef.get() : null;
            if (videoController != null) {
                videoController.stopAutoPlayAnimation();
            }
            return null;
        }
    }

    final class RequestPositionRunnable implements Runnable {
        private WeakReference<VideoController> videoControllerRef;

        RequestPositionRunnable(VideoController videoController) {
            this.videoControllerRef = new WeakReference(videoController);
        }

        public final void run() {
            VideoController videoController = this.videoControllerRef.get();
            if (videoController != null) {
                if (videoController.mUsingMediaPlayer != null) {
                    if (videoController.mDuration <= 0) {
                        videoController.mUsingMediaPlayer.requestDuration();
                    }
                    videoController.mUsingMediaPlayer.requestCurPosition();
                }
                videoController.mWeakHandler.postDelayed(this, 600L);
            }
        }
    }
}

